You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cascade-save relations have to be hydrated to models before saving, only to be dessicated into their PKs (or FKs from the other perspective) on save.
It would be helpfully efficient if passing an array of IDs would skip the model, presumably allowing the database itself to catch integrity violations.
I haven't worked out a simple way of doing this, hence vague request instead of specific idea with code attached :)
The text was updated successfully, but these errors were encountered:
It is dangerous to assume the database will enforce integrity. Underlying could be MySQL/MyISAM, which doesn't enforce anything. Also, hydrating to models makes sure the defined observers on those models will be triggered, which will not happen if you bypass the ORM logic.
My thinking was simply to avoid having models at all. Not sure whether it is correct to say that one could simply fake models with IDs in order to get them into the database, but I suspect it is, which means there is really no difference to ORM whether you give it an array of objects with PK values, or simply an array of PK values. There comes a point where creating an object for every related row is so inefficient you get into workarounds.
Point is that if you do this, you create inconsistent behaviour in ORM, as some things that are supposed to happen no longer happens. It could be that the related model I want to add isn't mine, and/or has internal logic (that I don't want to know) that needs to be executed on insert (like for example an observer_slug). This doesn't happen if you only inject the new FK's.
If you insist, use a DB query for that. If needed, hide the DB logic in a model method.
Cascade-save relations have to be hydrated to models before saving, only to be dessicated into their PKs (or FKs from the other perspective) on save.
It would be helpfully efficient if passing an array of IDs would skip the model, presumably allowing the database itself to catch integrity violations.
I haven't worked out a simple way of doing this, hence vague request instead of specific idea with code attached :)
The text was updated successfully, but these errors were encountered: