Non-persistent Entity Help

Hi CUBA Team,

I’ve got a requirement where I want to be able to show de-normalized data in a screen for the user to select. Say I have a schema that is Customer, Order, and Product tables. A Customer has Orders and an Order has Products. I need to be able to show a list of every Customer, Order, and Product combination in one grid. I’ve created a non-persistent entity for this with associations to Customer, Order, and Product as properties but I’m unsure of the best way to populate it without having to do a lot of selectById calls.

I’m thinking it might be better to just work with simple data types (Customer.id, Customer.name, Order.id, Order.name, etc) on my non-persistent entity instead of associations, making the select query easier, but I wanted to see if there’s a more recommended approach.

Thanks as always.

Hi Ryan,

I think you don’t need a extra Non-Persistent entity to do what you want.
I guess your existing entities have already the relations between each other?

You can create a seperate view for the Customer entity which includes all necessary related properties also from the related enties.
In your UI (table or grid) you have to build a datasource and select this created view. Use this datasource in your grid.

Please let me know if you need more details.

CU
Steven

Hi Ryan,
I’m a bit late with my answer, but anyway (almost the same as Steven suggested):

What about just selecting Orders:

select o from myapp$Order o where ...

and using paths to related attributes in the grid:

name
customer.name
product.name

Here I assume that Order has many-to-one references to Customer and Product.
If Order has a collection of Products (i.e. Product has order attribute and ORDER_ID column), you could select Products:

select p from myapp$Product p where ...

and columns will be:

name
order.name
order.customer.name