mongoid / origin

A Ruby DSL for building MongoDB queries
http://mongoid.org/en/origin/index.html
MIT License
62 stars 29 forks source link

Pushing a document onto one-sided N:N relation no longer updates parent #64

Closed mgartner closed 11 years ago

mgartner commented 11 years ago

The release of origin 1.0.11 has left me a little bit lost. In one of my apps, pushing a document onto a one-sided N:N relation doesn't update the document being pushed to. For example:

class Band
  include Mongoid::Document
  has_and_belongs_to_many :tags
end

class Tag
  include Mongoid::Document
end

band = Band.create
tag = Tag.first

band.tags << tag

# Before the release of origin 1.0.11, the band variable would be updated and the below would
# print "1". 
puts band.tags.count  # => 0

band.reload
puts band.tags.count # => 1

However, I've tried to rigorously reproduce the bug in a new app, but am unable to do so, and I believe I've used the same DB structure exactly. I'm baffled as to why I can't reproduce it.

I believe the issue can be traced to the commit fd6ede1, though I have limited knowledge as to the details of the source code.

Any ideas about this would be much appreciated.

durran commented 11 years ago

Which version of Mongoid are you running. In order for this update of Origin to play nicely you'd need to be on Mongoid 3.0.14, since we handle the changes after this commit: https://github.com/mongoid/mongoid/commit/ba4f54da3a27ce36b641d54e728e3ce56f69de19

mgartner commented 11 years ago

I'm running off the master branch instead of a stable release. But it looks like that contains that commit, correct?

durran commented 11 years ago

Just tested in Mongoid master and 3.1.0-stable and this code is correctly returning 1 for the counts.