Chromia
Start Building

09 / 26Part 2: Add a related entityBeginner

Define the book review entity

With the book entity in place, you can add a second entity, book_review, to store reviews of those books. The model looks like this:

Adding the book review entity

Open src/main/entities.rell and add the following definition for book_review:

src/main/entities.rell
entity book_review {  index book: book;  reviewer_name: text;  review: text;  rating: integer;}

Breakdown of the code

  • entity keyword: Declares a new entity, comparable to creating a table in a SQL database.
  • index book: book;: This attribute references a book, connecting each review to its book. The index keyword speeds up queries that go through this relationship.
  • reviewer_name: text;: Holds the name or alias the reviewer chooses to use.
  • review: text;: Holds the review itself as text.
  • rating: integer;: Holds the numeric rating given in the review.

These attributes are all you need to start storing book reviews in your Chromia app.

Written for this site from Chromia’s public course. Code samples are the course’s own.