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:
- 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.
- 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).
- Create new NestedDatasource for related items(Orders):
View relatedItemsView = new View(item.getClass()) .addProperty(relationToSelect, relatedItemsDs.getView()); Datasource masterDs = new DsBuilder(this.getFrame().getDsContext()) .setJavaClass(item.getClass()) .setView(relatedItemsView) .setId("dsMaster") .buildDatasource(); masterDs.setItem(item); NestedDatasource relatedItemsNestedDs = (NestedDatasource) new DsBuilder(this.getFrame().getDsContext()) .setMaster(masterDs) .setProperty(relationToSelect) .setId("nestedDs") .buildCollectionDatasource(); dsContext.unregister(relatedItemsDs); dsContext.register(relatedItemsNestedDs); this.getFrame().getDsContext().refresh(); 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!