How to create association in a Java Action for new projects

0
Let's say I do the following Parent parent = new module.proxies.Parent(super.getContext()); Child child1 = new module.proxies.Child(super.getContext()); Child child2 = new module.proxies.Child(super.getContext()); How do I add child1 and child2 to the parent object (assuming there is an one-to-many association between them). Also is there a way to get the name of the association without hard coding (a constant somewhere like the MemberNames enum)?
asked
2 answers
3

Justin,

You can set the value of a member including associations with something like this:

child1.getMendixObject().setValue(getContext(), child1.proxies.parent.MemberNames.child_parent.toString(), parent.getMendixObject().getId());

From the proxy object you first get the IMendixObject, then set the value using the child proxy object to get the specific member (the association between child and parent) and then set the value. This is a method that is not hardcoded in the sense that the action will break on the compilation of the project if the chid_parent association is changed or deleted.

answered
5

The setter is on the child. I just didn't see it

child.setParent_Child(parent);
answered