Define the book review entity
Now that we've created the book
entity, the next step is introducing the book_review
entity. This entity will enable
us to record book reviews. The model is as follows:
Add the book review entity
To define the book_review
entity, open the file src/main/entities.rell
and add the following code:
src/main/entities.rell
entity book_review {
index book: book;
reviewer_name: text;
review: text;
rating: integer;
}
Breakdown of the code
entity
keyword: Defines a new entity, similar to creating a table in a SQL database.index book: book;
: Theindex
keyword is used to optimize queries involving thebook
relation. This attribute refers to abook
, creating a link between a book and its reviews.reviewer_name: text;
: Allows users to enter their name or alias as a reviewer.review: text;
: Stores the textual content of the review.rating: integer;
: Captures the numerical rating given to the book review.
You can begin recording book reviews with these attributes in your Chromia-based app. For a deeper understanding of managing relationships between entities, check out our Understand relationships in Rell course, which covers building and optimizing table relationships.