objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Add objects to ToMany by ID only #532

Open Paroca72 opened 1 year ago

Paroca72 commented 1 year ago

Hello,

It should be very useful to have inside ToMany class a method addId to add the entity reference directly by the id. Now have just add that force the programmer to insert a whole entity. But in many case what have are the ids and this force to load all the related entities before can add them as relations.

the ToOne already provide this function passing by targetId.

Thanks Sam

greenrobot-team commented 1 year ago

Thanks for the suggestion!

We could enable this by exposing InternalBoxAccess.relPut (directly or through a helper class). Changing ToMany itself does not seem a good idea as it is a list of objects.

A potential workaround: if the objects to be added all have an ID (e.g. the ID is not zero or null) it should be possible to just add objects with an ID set (and other values null or default) and save.

If others would like to have this feature, please thumbs up the first comment! This helps us track interest.