I’m working on a feature where I need to manage and synchronize associations between two entities: Children and Pets. I’m facing challenges in keeping these associations updated in both directions and would appreciate insights or suggestions from the community.
- I have two tables in my database: Child and Pet.
- Each Child can have multiple associated Pets, and each Pet can be associated with multiple Children. The associations are many-to-many.
- The Child table has a field associated_pets, a list of Pet type.
- The Pet table has a field associated_to_children, a list of Child type.
- On the Pet profile page in the dashboard, I want to enable users (parents) to edit the children assigned to each pet.
- When a child is added or removed from a pet’s associated_to_children list, I need to simultaneously update the associated_pets list in the corresponding Child’s record, and vice versa.
- The children being managed are always the current user’s children.
I’m looking for methods that might be more effective, particularly in handling many-to-many updates. I have found the Multi Dropdown element to work to keep the Pet.associated_to_children in sync, but not sure how to update Child.associated_pets
If I understand correctly, you can just update two things at a time and things will be in sync. Simply, whenever you add a pet to a child, then you will also add the child to that pet’s list. And whenever, removed, you will do the same.
See the demo below:
It is simply doing the thing I explained to you. Updating two things at a time. For example, look at the pet association:
All of them are similar, both associating and removing.
One thing I noticed is you can’t add a remove button to the internal repeating group and have access to Current Pet and Current Child at the same time. That’s why I did the removal via dropdown. Someone, please let me know if I missed anything on that end
Here is the app if you want to check the details:
Thank you very much for taking the time to reply and try to help. Your example has given me ideas. I’ll continue to study it and report back. It would be great to be able to remove via the dropdown - maybe somehow I can use the Multi Dropdown to make that work. Thanks again.
@dballiet another approach might be to use database triggers from backend workflows. I’m not sure but I have a feeling it may be less WU consumption if implemented properly than changing two different things at the same time.
Another alternative is to not bother with relying on two different lists, and just use one, since if for example you only did a data field on the Pet data type that is of type Child which would be a list to have a list of associated children for the pet, and you wanted to then show a child all of the Pets they are associated with you can easily retrieve that data by
doing a search for Pets each items associated child contains current child
Also, look into any implications related to the use of a data field that is a list, such as slow down in retrieval when the list grows.