Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relations to be set with PK array #242

Open
Altreus opened this issue Mar 26, 2013 · 3 comments
Open

Allow relations to be set with PK array #242

Altreus opened this issue Mar 26, 2013 · 3 comments

Comments

@Altreus
Copy link

Altreus commented Mar 26, 2013

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 :)

@WanWizard
Copy link
Member

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.

@Altreus
Copy link
Author

Altreus commented Apr 29, 2013

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.

@WanWizard
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants