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 06 9:43 AM - edited 2023 Sep 07 9:57 AM
2023 Sep 07 7:34 AM
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 07 9:57 AM - edited 2023 Sep 07 10:09 AM
Thanks! fixed 🙂
btw used ChatGTP to generate some dummy data
2023 Sep 06 11:02 AM - edited 2023 Sep 06 11:08 AM
2023 Sep 06 12:21 PM
2023 Sep 06 12:37 PM - edited 2023 Sep 06 12:39 PM
2023 Sep 06 1:01 PM - edited 2023 Sep 06 1:04 PM
2023 Sep 06 1:59 PM
2023 Sep 06 3:19 PM
2023 Sep 06 3:30 PM
2023 Sep 06 4:01 PM
2023 Sep 06 4:48 PM
2023 Sep 07 7:55 AM
Some pieces are not accurately represented in your model. Check on the relationships between the entities and note that Answers in not an independent entity but an Aspect that exists in the context of a Questions entity.
2023 Sep 06 4:55 PM
2023 Sep 06 5:23 PM
2023 Sep 07 7:48 AM
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 10:52 PM
2023 Sep 06 8:02 PM
2023 Sep 06 8:35 PM - edited 2023 Sep 06 8:40 PM
<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"/>
<Property Name="createdBy" Type="Edm.String" MaxLength="256"/>
<Property Name="modifiedAt" Type="Edm.DateTimeOffset"/>
<Property Name="modifiedBy" Type="Edm.String" MaxLength="256"/>
<Property Name="title" Type="Edm.String" MaxLength="255"/>
<Property Name="description" Type="Edm.String" MaxLength="100"/>
<NavigationProperty Name="questions" Type="Collection(DevChallengeService.Questions)" Partner="test"/>
<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"/>
<Property Name="text" Type="Edm.String" MaxLength="255" Nullable="false"/>
<NavigationProperty Name="answer" Type="DevChallengeService.Questions_answer" Partner="up_">
<OnDelete Action="Cascade"/>
<ReferentialConstraint Property="ID" ReferencedProperty="up__ID"/>
</NavigationProperty>
<NavigationProperty Name="test" Type="DevChallengeService.Tests" Partner="questions">
<ReferentialConstraint Property="test_ID" ReferencedProperty="ID"/>
</NavigationProperty>
<Property Name="test_ID" Type="Edm.Guid"/>
</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">
...
</NavigationProperty>
<Property Name="up__ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="ID" Type="Edm.Guid" Nullable="false"/>
<Property Name="text" Type="Edm.String" MaxLength="255"/>
</EntityType>
2023 Sep 06 9:13 PM
2023 Sep 07 7:45 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 07 6:44 PM
So thats why the expand was not working! Thanks for the correction.
2023 Sep 06 10:05 PM
2023 Sep 07 2:56 AM
2023 Sep 07 4:16 AM - edited 2023 Sep 07 4:09 PM
2023 Sep 07 7:27 AM
In the Tests entity, there is a tiny piece missing in your model (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 07 4:05 PM
Hi Dinah,
It is fixed, thanks for the inputs
2023 Sep 07 6:31 AM
2023 Sep 07 7:01 AM
2023 Sep 07 8:06 AM
2023 Sep 07 9:39 AM
2023 Sep 07 10:41 AM
2023 Sep 07 10:49 AM
2023 Sep 07 11:03 AM
2023 Sep 07 11:07 AM
2023 Sep 07 12:48 PM
2023 Sep 08 5:30 AM
A tiny piece missing in your model in the Tests entity - (The attribute Partner in your <NavigationProperty Name="questions">). Hint: backlink
2023 Sep 11 2:50 PM
Thank you for pointing this out:
2023 Sep 07 1:04 PM