This blog post was created with the help of an AI assistant π€. I want to keep it simple and easy to understand so developers who are new to Uniface can follow along.
What are related entities?
In Uniface, when you build an application, you often deal with multiple entities (like tables in a database). If one entity is connected to another (for example, "Customer" and "Orders"), we say they have a relationship.
In Uniface 10.4, when entities are related, you must nest them in the component data structure. This means the outer entity contains the inner one in the structure. Example: a Customer can have multiple Orders.
How Uniface handles relationships
- The compiler automatically recognizes the relationship.
- The primary key of the "one" entity becomes the foreign key of the "many" entity.
- Uniface keeps these keys in sync for you β no extra work needed! π
Good practices
- Define only the primary key in the outer entity, not the foreign key in the inner one, unless absolutely needed.
- Avoid writing ProcScript that changes foreign keys. Uniface handles this automatically.
- Entities can be nested up to 8 levels deep and each entity can have up to 64 child entities.
Example
Letβs say we have two entities: Customer and Order.
Component Data Structure:
Customer (Entity)
βββ Order (Entity)
Here Uniface knows that CustomerId from Customer is also used as a foreign key in Order. Uniface will automatically copy the correct value of CustomerId when you create a new Order. No need to write code for this! π
Why is this useful?
By letting Uniface manage the relationship automatically, you make your application safer, cleaner, and easier to maintain. You can focus on the business logic instead of handling keys manually.
Conclusion
In short: Nest related entities, define only the needed keys, and let Uniface do the heavy lifting. This will help you avoid mistakes and keep your code simple π‘.
Written with the assistance of an AI assistant π€
uniface components entities procscript
Top comments (0)