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

2 models referencing each other need 2 assignements #191

Open
yarmand opened this issue Mar 19, 2015 · 2 comments
Open

2 models referencing each other need 2 assignements #191

yarmand opened this issue Mar 19, 2015 · 2 comments

Comments

@yarmand
Copy link

yarmand commented Mar 19, 2015

With relational DB, a 1-N relation only need a foreign key to retrieve relation content on both side. With documents DB a search on a foreign key is non efficiant.
My proposal is to automaticaly assign a reference on both sides.
See more details in this pull request

@samlown
Copy link
Member

samlown commented Mar 23, 2015

Hey. Thanks for contributing this! I like the look of what you're doing and would like to check it out as soon as possible.

Given the atomic or non-transactional nature of CouchDB, I'm slightly reluctant to add this as a feature that is activated by default. I wouldn't want to give the false impression of consistency. There is no guarantee that both documents would be saved at the same time, even less so if there is validation on both models.

@yarmand
Copy link
Author

yarmand commented Mar 24, 2015

yes, I was wondering the same thing.
I was thinking of triggering back assignement only when there is an explicit usage of the :reverse_association.

About validation.
When object A is saved, it will trigger a save on object B. Any failed validation on A will block the process.
Most of the time B will come from a db read to get updated and saved.
The only problematic case I see it the creation of both object at the same time, so B can be affected to an association of A before being validated once. There is a way to detect this with B.new?, but I'm not sure about the what to do here:

  • trigger an exception (B need to be saved befroe being affected to A)
  • do not do the revert association, but it create silent inconsistency.

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