Nested datasource question

Hello,

I need some help with a basic problem.
I have an association with many to many relationship. For this Studio automatically generates a nested collectiondatasource and the editor wizzard generates a nested table with add / remove buttons. I really need the nested table to be displayed in a custom order. Because the nested datasource does not allow any queries I created my datasource as a non-nested one, by using this query:

select p from myapp$Projects p join p.customers c where c.id = :ds$customersDs order by p.date_start, p.id

It works for displaying nested table in the desired order and editing it, but add and remove fail. For example when removing a row (customer) from the nested table, the customer is removed cascaded from everywhere. This behaviour has to do with the fact that the datasource is not nested anymore, although the query looks ok.

Thanks,
Tudor

1 Like

Thanks Konstantin.

It works with @OrderBy annotation. I missed that part in Studio, sorry.
And for the general purpose of modifying the query of a nested datasource, is my sample query example ok?

> And for the general purpose of modifying the query of a nested datasource, is my sample query example ok?

Sorry, didn’t catch. Nested datasources cannot contain queries, they are just containers for already loaded collections. If you mean a dependent standalone datasource then yes, the query looks correct. Especially since you reported that it works :slight_smile:

It worked partially :slight_smile: - editing was fine, but adding and removing no.
I just wanted to know for me or for other users : in a many-to-many association (which results in a nested datasource) what is the recommended way to make changes to the loaded collection - for example applying an additional filter.

If you use a standalone datasource for the collection and hence don’t have COMPOSITION behavior, you a free to filter the collection by specifying an appropriate query or using the generic Filter component.

But if the datasource is nested, you cannot filter it without without copying the content to another datasource programmatically. It complicates things a lot. We’ve started working on a new data layer for the UI where will be no such restrictions, but it will be available only in the next major release - 7.0.

Hi Tudor,

Probably you had a composition behavior, and it doesn’t work now because you have made your datasource standalone.

Try to turn it back to nested and sort the collection (it should be a List) in the @OrderBy annotation. It can be done in the entity attribute editor in Studio.

Sorry to relive this post, but I’m very interested in this functionality and therefore I wonder if it will be available in version 7

Yes it will. See for example this test.