Hello, I am having a hard time with saving an object while adding a relationship to the parent object
I have two data tables: MovementPattern, and Exercises, which have a one to many relationship (e.g., the bench press may fall under a movement pattern called “pressing”. I am trying to create a form where I can add a new exercise and both save it in the exercise data table while also adding it’s MovementPattern parent relationship. This is the logic I have assigned to the submit/save button on my form:
In the above image, “SelectedCategory” was set on my Movement Pattern data table logic shown below:
When I run it, its not saving the new exercise name (exname is assigned to the value logic handler for that input), or setting the relationship (obviously if its not creating it it wont create a relationship lol). Any help is really appreciated. I’m very new to this and want to understand what I am doing wrong. Thanks!
Hi Brian,
Welcome to the community!
At the time when the “Add Object Relations” runs, both parent and child objects must already be in the database. In the logic screenshot you shared, it shows that the child object is new and doesn’t have objectId
. This is the reason why the relationship is not established - the system doesn’t know what child to set the relationship with. As an alternative (if you want the child object to be persisted and the relationship should be created, consider using the DeepSave block/API.
For more information on setting 1:N relationships, watch the following video:
Regards,
Mark
Hi Mark, thank you! Looking forward to this journey.
So I had actually watched that video already and can’t seem to figure out where the new city is being created in the Codeless logic and saved in the database prior to being placed within the add relation block.
Is it in the bulk create block? I assumed it was and thought create object was the same as that but for single objects instead of multiple (as shown in the demo).
I appreciate your help!
Hello @Brian_Minor!
Yes, that’s right, it happens in the Bulk Create
block, while the Create Object
block simply creates the object data type. If you need to save only one entity, you can use the Save Object block in Backendless
.
Regards,
Alexander
Ah ok that makes sense. So what would be required to change in the image below? It is saving the object but isn’t establishing the relation. I really appreciate your help!
The only thing I would change is passing a list into the children
connector (it expects a collection of children):
Awesome. It works now, thank you!
So anytime I’m adding to an existing list of relations I would use the create list? I had assumed that was for new lists.
Appreciate your help!
You are welcome.
Yes, the operation expects a list for the children
connector.
Regards,
Mark