Working with NestedDatasource Programmatically

I have the One-To-Many Association Customer(One) and Orders(Many). So Cuba Platform creates the field customer_id in Order table. The problem is that when I add programmatically new orders to the customer and then use dataManager.commit(customer) - nothing is updated in the database (I guess because dataManager doesn’t know anything about Order and its relationship with Customer).
My main goal is to show collection of related entities in new tab as a part of generic navigation. So I pass the parent item object(current Customer I am working with) as window parameter to related entities browser screen(orders-browse) and want to show, filter and manipulate corresponding entities(Orders). In order to do so, I have tried a couple of approaches:

  1. Filter Orders with QueryFilter - works: show related items, add and exclude actions with custom handler using dataManager, but only for many-to-many relationship; doesn’t work: filter(rewrites by query filter), add and exclude actions for one-to-many relationship.
  2. FIlter Orders by Query with “where” - works: show related items, filter. doesn’t work: add and exclude actions for one-to-many relationship, inserting new items in datasource doesn’t update the inserted object(customer_id of insterted order is null).
  3. Create new NestedDatasource for related items(Orders):

            View relatedItemsView = new View(item.getClass())
                    .addProperty(relationToSelect, relatedItemsDs.getView());
            Datasource masterDs = new DsBuilder(this.getFrame().getDsContext())

            NestedDatasource relatedItemsNestedDs = (NestedDatasource) new DsBuilder(this.getFrame().getDsContext())


            Table relationsTable = (Table) this.getFrame().getComponent(relationToSelect + "Table");
            relationsTable.setDatasource((CollectionDatasource) relatedItemsNestedDs);

works: add, exclude actions; doesn’t work - filter (CollectionPropertyDatasourceImpl doesn’t support QueryFilter).

And one more question: is it possible to automatically write the datasource changes directly to the database without confirming the changes with “OK” window actions, or how to confirm the changes programmatically?

Thanks for your answer in advance!


I can give you a quick answer only to your last question: use getDsContext().commit() in your screen controller to save all changed entities to the database.

As for the first question, please create a small sample project and attach it here along with a description of what you are going to achive and what doesn’t work for you.