DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Uniface 10.4 - Understanding Related Entities

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)