First we need to analise the requirements and create the data model. By analysing the requirements, we determine that the central data structure is the book. We create an entity for the book that has a title and a stock. The stock increases when a book instance is created and decreses when it is deleted.
That might look something like:
Now, as we need to add some relationships, we see that the requirement says that each book has an author. There are two ways we can handle this: first, we can add a property author directly to the book entity. However, this approach would cause redundancy if we need to track multiple books by the same author. The better approach is to create a separate entity for authors and establish a relationship between the book and author.
Books can belong to multiple categories (e.g., "Science" and "Fiction"), and categories can contain multiple books. This creates a many-to-many relationship. To manage this, we introduce a join table called book_category to link books and categories.
Note: The "uuid" field is automatically generated.
The book_instance entity represents individual copies of books available for borrowing. Each instance has an "in_stock" field to track availability after borrowings and returns. The "in_stock" field is of type int, with a value of 1 (true) when the instance is created and 0 (false) when the instance is borrowed. After the customer returns the copy, the "in_stock" field will revert to 1, indicating that the book is back in stock.
The book_history entity tracks the borrowing and returning of books. It includes:
The book_history_type entity categorizes the types of history records, with the name field having values like "Borrowed" or "Returned".
The customer entity stores customer details, including a "total_tax" field, which tracks the total amount the customer owes for late book returns.
In this lesson, we will guide you step by step through creating the library app’s entities, search views, edit views, menus, catalogs, event listeners, and entity actions. All these entities are essential for the app to function properly. It’s recommended to complete the lesson using the knowledge from previous lessons and the key content here and in upcoming modules. Note that we won’t cover all validations (creating them is optional if you choose to do so), but we will cover the most important aspects.
The first step in designing a Kodall app is constructing the data model. The data model consists of entities, properties, and relationships between entities.
Now that the data model is defined, it’s time to create the entities. A customization set will be created for each entity in the data model. This set includes the entity along with its properties and relationships.
For this example, we will create a single customization set called "book" that includes all the entities described in the previous step. However, if it’s easier, you can create a separate customization set for each entity.
To create a customization set, you will need to follow the steps presented in Lesson 1 the Products.
For example, the book entity has the following properties:
| Entity name | Property name | Property type |
|---|---|---|
| book | title | string |
| book | stock | int |
and the book_instance entity would have:
| Entity name | Property name | Property type |
|---|---|---|
| book_instance | barcode_number | string |
| book_instance | in_stock | int |
in_stock field should be of type bool, but we will use int instead. Since the boolean type is unavailable, it will take values 0 (false) and 1 (true) as integers to manage borrowing and returning.For more information on entities, check the Entities page in the Develop App module.
The relationships between entities are essential for their interaction. Here’s a breakdown of each relationship and how it aligns with business needs:
| Relationship name | Entity name | Type name | Foreign entity name |
|---|---|---|---|
| author_book | author | 1:n | book |
| book_book_category | book | 1:n | book_category |
| book_book_instance | book | 1:n | book_instance |
Continue defining the remaining relationships to ensure the proper functionality of the app.
To create relationships for this table, follow the steps presented in Lesson 2 the Invoices. After the relationships have been created, publish the customization set. To publish an entity, see Publishing the entities from Lesson 1 the Products .
For more details, see the Documentation → Develop App → Customization Set.