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

Bumping to mongoid 5 #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

matheus208
Copy link

Pull request to add compatibility to Mongoid 5.

Changes:

  • Since Mongoid 4, Versioning is not available out of the box, so I had to add a check before including it.
  • Mongoid 5 complained about using the foreign_key id on has_* relations. So I changed it to send the related model's name instead (which is the standard way of doing it on Mongoid 5). This might break older versions.

All tests are passing (once again, using Mongoid 5. I haven't used older versions). Is there an easy way to test all Mongoid versions?

@davidsevcik
Copy link
Contributor

Will have a look on testing it with older Mongoid.

matheus208 added 2 commits October 29, 2015 13:31
…detect what it should record on the database. So we need to stick with just adding changed_with_relations in order to not break anything else.
@matheus208
Copy link
Author

Okay... I found a bug with Mongoid 5. When you save an attribute of a nested model, it will push both the nested model and the change on the "changed?" list.

For efficiency reasons (I suppose), Mongoid uses this to only save what has been changed on the document so far, resulting in it trying to update the model AND the model's attribute on the same requests. Which Mongo does not like, throwing an error.

"Mongo::Error::OperationFailure: Cannot update **MODEL** and **MODEL_ATTRIBUTE** at the same time (16837)"

The only thing I can think of is drop the aliasing of :changed? and :changes and stick to using :changed_with_relations and :changes_with_relations.

That might be a deal breaker for this pull request being accepted... What are your thoughts on it?

@matheus208
Copy link
Author

Also, I found a bug that is probably happening on the master branch as well.

When you save a document that has a has_one or has_many, Mongoid calls the after_save callback multiple times in an infinite loop and a stack level too deep error is thrown.

I'm trying to figure out why/fix it, but I'm having a hard time.

@mateuspontes
Copy link

@matheus208 hey, do you like to continue this PR? You removed alias_method_chain and I think it is good, but you cann't see relation_changes anymore without chain.

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

Successfully merging this pull request may close these issues.

3 participants