2023 Sep 06 8:49 AM - edited 2023 Sep 06 12:17 PM
If you have not checked out the initial blog post for this challenge, please do so and get your development environment set up as outlined in the post.
We are working on creating test(s) for a particular course/subject. We need to have a pool of questions (related to the course/subject) that we can pick from to make up a test. A single test can be associated with several questions, but each question belongs to only one test. Through the relationship between tests and questions, one should be able to access all questions related to a specific test and easily access the specific test to which a question belongs (hint: backlink).
Additionally, we need to have a right answer for every question and a question can only have one right answer. An answer cannot exist without a question. If a question is deleted, so should the linked answer be deleted.
We will get started with database modeling using SAP CAP. We delve into the architecture, carefully defining two core entities and an aspect respectively: "Tests," "Questions," and "Answers".
Tests Entity – serves as a container for organizing different test cycles. Each entry within the Tests entity represents a unique object with attributes such as test ID, title, description, createdAt, createdBy, modifiedAt, modifiedBy and any other vital information relating to tests. A single test can have many questions. This entity allows us to categorize and manage tests efficiently, facilitating easy retrieval and presentation of tests data.
Questions Entity – serves as a repository for individual questions comprising the intellectual content of our tests. Each entry in the Questions entity comprises attributes such as ID, text, and any other vital information relating to questions. Many questions can be associated with a single test, but each question belongs to only one test (that is, two different tests cannot have the same question). Centralizing questions in this entity allows us to create a cohesive reservoir of knowledge that can be easily linked to a Test instance.
Answers Aspect– records the correct answer to a particular question. Each record in this aspect corresponds to a correct answer linked to a specific question. Each entry in the Answers aspect comprises attributes such as ID, and text. The separation of answers from questions reinforces data integrity.
Why an Aspect instead of Entity for the Answers?
Aspects are well suited for representing data that does not have a distinct identity of their own. In our schema design, the answers cannot exist without a question. For example, if a question record is deleted, we would want an answer associated with it to be deleted as well. Using an aspect in this case allows us to associate answers data directly with questions without creating a separate entity.
Our goal is to perform entity-relationship modeling based on the above entities' description and then populate initial data in csv files to be used in the next tasks. Below is a visual representation providing details (entity properties and data types) to help with the modeling.
Here are some resources to guide you through this task:
CDS Command line Interface tools
Run the application (cds watch). Note that the initial errors displayed in the terminal after our development environment setup should have disappeared.
Click on the URL that the server is listening on to access the page displayed below:
Under Service Endpoints, click on $metadata and post a screenshot into this discussion thread. Collapse other sections and focus on the <EntityType Name=”...”> tags as shown below.
2023 Sep 11 12:31 PM
Check your Tests entity, there is a tiny piece missing in your model (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 11 12:22 PM
2023 Sep 11 2:03 PM
2023 Sep 11 3:50 PM
2023 Sep 11 4:26 PM
2023 Sep 11 7:22 PM
2023 Sep 11 11:59 PM - edited 2023 Sep 12 12:38 PM
2023 Sep 12 5:20 AM
2023 Sep 12 10:42 AM
2023 Sep 12 11:16 AM - edited 2023 Sep 12 11:34 AM
2023 Sep 12 11:29 AM - edited 2023 Sep 12 11:31 AM
2023 Sep 12 12:42 PM
2023 Sep 12 8:18 PM
There is a tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 13 9:22 AM
Thank you for you comment.
Here is a revised version:
2023 Sep 12 6:36 PM
2023 Sep 12 7:56 PM
2023 Sep 12 8:25 PM
2023 Sep 13 5:14 AM
2023 Sep 13 7:03 AM
2023 Sep 13 9:57 AM
2023 Sep 13 3:37 PM
2023 Sep 13 8:59 PM
2023 Sep 13 9:25 PM
2023 Sep 13 11:44 PM
2023 Sep 14 3:45 AM
2023 Sep 14 11:33 AM
There is a tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 14 11:20 AM
2023 Sep 14 2:18 PM
2023 Sep 14 10:27 PM
There is a tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 16 12:29 PM
Hello Dinah, I have corrected the same
2023 Sep 14 7:43 PM - edited 2023 Sep 14 7:44 PM
2023 Sep 14 10:28 PM
There's a tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 15 6:03 AM - edited 2023 Sep 15 6:03 AM
Hello Dinah. I have corrected it !
2023 Sep 14 7:53 PM
2023 Sep 14 8:20 PM
Week 1 solution-
2023 Sep 15 12:51 AM
2023 Sep 18 9:01 AM
There is something missing: the questions entity does not have a relationship with the Questions_answer entity. A NavigationProperty of the answer should exist in the Questions entity. Something similar to the <NavigationProperty name="test"....> in the Questions entity.
2023 Sep 15 3:30 PM
Hi,
I'm missing the Questions_answer entity, I have the aspect , and the Backlink, but i don't see it in the metadata 😞
Saludos,
2023 Sep 18 7:54 AM
Hi,
It looks like you have not modeled the relationship between questions and answers entities. Hint: a question can only have one answer and an answer cannot exist without a question. Compositions vs Associations
2023 Sep 15 11:24 PM - last edited on 2023 Sep 15 11:37 PM by Former Member
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/Common.xml">
<edmx:Include Alias="Common" Namespace="com.sap.vocabularies.Common.v1"/>
</edmx:Reference>
<edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1"/>
</edmx:Reference>
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/UI.xml">
<edmx:Include Alias="UI" Namespace="com.sap.vocabularies.UI.v1"/>
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="DevChallengeService">
<EntityContainer Name="EntityContainer">
<EntitySet Name="Tests" EntityType="DevChallengeService.Tests">
<NavigationPropertyBinding Path="questions" Target="Questions"/>
<NavigationPropertyBinding Path="SiblingEntity" Target="Tests"/>
</EntitySet>
<EntitySet Name="Questions" EntityType="DevChallengeService.Questions">
<NavigationPropertyBinding Path="test" Target="Tests"/>
<NavigationPropertyBinding Path="answer" Target="Questions_answer"/>
</EntitySet>
<EntitySet Name="Questions_answer" EntityType="DevChallengeService.Questions_answer">
<NavigationPropertyBinding Path="up_" Target="Questions"/>
</EntitySet>
</EntityContainer>
<EntityType Name="Tests">
<Key>
<PropertyRef Name="ID"/>
<PropertyRef Name="IsActiveEntity"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="createdAt" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="createdBy" Type="Edm.String" MaxLength="256"/>
<Property Name="modifiedAt" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="modifiedBy" Type="Edm.String" MaxLength="256"/>
<NavigationProperty Name="questions" Type="Collection(DevChallengeService.Questions)" Partner="test"/>
<Property Name="title" Type="Edm.String"/>
<Property Name="description" Type="Edm.String"/>
<Property Name="IsActiveEntity" Type="Edm.Boolean" Nullable="false" DefaultValue="true"/>
<Property Name="HasActiveEntity" Type="Edm.Boolean" Nullable="false" DefaultValue="false"/>
<Property Name="HasDraftEntity" Type="Edm.Boolean" Nullable="false" DefaultValue="false"/>
<NavigationProperty Name="DraftAdministrativeData" Type="DevChallengeService.DraftAdministrativeData" ContainsTarget="true"/>
<NavigationProperty Name="SiblingEntity" Type="DevChallengeService.Tests"/>
</EntityType>
<EntityType Name="Questions">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<NavigationProperty Name="test" Type="DevChallengeService.Tests" Partner="questions">
<ReferentialConstraint Property="test_ID" ReferencedProperty="ID"/>
</NavigationProperty>
<Property Name="test_ID" Type="Edm.Guid"/>
<Property Name="text" Type="Edm.String"/>
<NavigationProperty Name="answer" Type="DevChallengeService.Questions_answer" Partner="up_">
<OnDelete Action="Cascade"/>
<ReferentialConstraint Property="ID" ReferencedProperty="up__ID"/>
</NavigationProperty>
</EntityType>
<EntityType Name="DraftAdministrativeData">
<Key>
<PropertyRef Name="DraftUUID"/>
</Key>
<Property Name="DraftUUID" Type="Edm.Guid" Nullable="false"/>
<Property Name="CreationDateTime" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="CreatedByUser" Type="Edm.String" MaxLength="256"/>
<Property Name="DraftIsCreatedByMe" Type="Edm.Boolean"/>
<Property Name="LastChangeDateTime" Type="Edm.DateTimeOffset" Precision="7"/>
<Property Name="LastChangedByUser" Type="Edm.String" MaxLength="256"/>
<Property Name="InProcessByUser" Type="Edm.String" MaxLength="256"/>
<Property Name="DraftIsProcessedByMe" Type="Edm.Boolean"/>
</EntityType>
<EntityType Name="Questions_answer">
<Key>
<PropertyRef Name="up__ID"/>
<PropertyRef Name="ID"/>
</Key>
<NavigationProperty Name="up_" Type="DevChallengeService.Questions" Nullable="false" Partner="answer">
<ReferentialConstraint Property="up__ID" ReferencedProperty="ID"/>
</NavigationProperty>
<Property Name="up__ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="text" Type="Edm.String"/>
</EntityType>
<Action Name="draftPrepare" IsBound="true" EntitySetPath="in">
<Parameter Name="in" Type="DevChallengeService.Tests"/>
<Parameter Name="SideEffectsQualifier" Type="Edm.String"/>
<ReturnType Type="DevChallengeService.Tests"/>
</Action>
<Action Name="draftActivate" IsBound="true" EntitySetPath="in">
<Parameter Name="in" Type="DevChallengeService.Tests"/>
<ReturnType Type="DevChallengeService.Tests"/>
</Action>
<Action Name="draftEdit" IsBound="true" EntitySetPath="in">
<Parameter Name="in" Type="DevChallengeService.Tests"/>
<Parameter Name="PreserveChanges" Type="Edm.Boolean"/>
<ReturnType Type="DevChallengeService.Tests"/>
</Action>
<Annotations Target="DevChallengeService.EntityContainer/Tests">
<Annotation Term="Common.DraftRoot">
<Record Type="Common.DraftRootType">
<PropertyValue Property="ActivationAction" String="DevChallengeService.draftActivate"/>
<PropertyValue Property="EditAction" String="DevChallengeService.draftEdit"/>
<PropertyValue Property="PreparationAction" String="DevChallengeService.draftPrepare"/>
</Record>
</Annotation>
</Annotations>
<Annotations Target="DevChallengeService.Tests/IsActiveEntity">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="DevChallengeService.Tests/HasActiveEntity">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="DevChallengeService.Tests/HasDraftEntity">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="DevChallengeService.Tests/DraftAdministrativeData">
<Annotation Term="UI.Hidden" Bool="true"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData">
<Annotation Term="Common.Label" String="Datos administrativos en borrador"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/DraftUUID">
<Annotation Term="UI.Hidden" Bool="true"/>
<Annotation Term="Common.Label" String="Borrador (ID técnico)"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/CreationDateTime">
<Annotation Term="Common.Label" String="Borrador creado el"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/CreatedByUser">
<Annotation Term="Common.Label" String="Borrador creado por"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/DraftIsCreatedByMe">
<Annotation Term="UI.Hidden" Bool="true"/>
<Annotation Term="Common.Label" String="Borrador creado por mí"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/LastChangeDateTime">
<Annotation Term="Common.Label" String="Fecha del último cambio en borrador"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/LastChangedByUser">
<Annotation Term="Common.Label" String="Autor del último cambio en borrador"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/InProcessByUser">
<Annotation Term="Common.Label" String="Borrador en proceso por"/>
</Annotations>
<Annotations Target="DevChallengeService.DraftAdministrativeData/DraftIsProcessedByMe">
<Annotation Term="UI.Hidden" Bool="true"/>
<Annotation Term="Common.Label" String="Borrador en proceso por mí"/>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>