Skip to content

Commit

Permalink
Merge in 2.3.0-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Oct 20, 2011
2 parents f475489 + ae96e29 commit 055e6ef
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,12 +5,23 @@ For instructions on upgrading to newer versions, visit

## 2.4.0 \[ In Development \] \[ Branch: master \]

### New Features

* Ranges can now be passed to #where criteria to create a $gte/$lte query under the
covers. `Person.where(dob: start_date...end_date)`

### Resolved Issues

* \#1333 Fixed errors with custom types that exist in namespaces. (Peter Gumeson)

## 2.3.2 \[ In Development \] \[ Branch: 2.3.0-stable \]
## 2.3.3 \[ In Development \] \[ Branch: 2.3.0-stable \]

### Resolved Issues

* \#1358 Fixed type error on many to many synchronization when inverse_of is
set to nil.

## 2.3.2

### Resolved Issues

Expand Down
13 changes: 13 additions & 0 deletions lib/mongoid/relations/metadata.rb
Expand Up @@ -243,6 +243,19 @@ def extension?
!!extension
end

# Does this metadata have a forced nil inverse_of defined. (Used in many
# to manies)
#
# @example Is this a forced nil inverse?
# metadata.forced_nil_inverse?
#
# @return [ true, false ] If inverse_of has been explicitly set to nil.
#
# @since 2.3.3
def forced_nil_inverse?
has_key?(:inverse_of) && inverse_of.nil?
end

# Handles all the logic for figuring out what the foreign_key is for each
# relations query. The logic is as follows:
#
Expand Down
6 changes: 4 additions & 2 deletions lib/mongoid/relations/synchronization.rb
Expand Up @@ -93,8 +93,10 @@ module ClassMethods #:nodoc:
#
# @since 2.1.0
def synced(metadata)
synced_save(metadata)
synced_destroy(metadata)
unless metadata.forced_nil_inverse?
synced_save(metadata)
synced_destroy(metadata)
end
end

private
Expand Down
3 changes: 2 additions & 1 deletion spec/app/models/article.rb
Expand Up @@ -9,5 +9,6 @@ class Article
attr_accessible :title, :as => [:default, :parser]
attr_accessible :is_rss, :as => :parser
attr_accessible :user_login
has_and_belongs_to_many :tags
has_and_belongs_to_many :tags, :validate => false
has_and_belongs_to_many :preferences, :inverse_of => nil, :validate => false
end
23 changes: 23 additions & 0 deletions spec/functional/mongoid/relations/synchronization_spec.rb
Expand Up @@ -6,6 +6,29 @@
[ Person, Preference, Article, Tag ].each(&:delete_all)
end

context "when the inverse of is nil" do

let(:preference) do
Preference.new(:name => "test")
end

let(:article) do
Article.new
end

before do
article.preferences << preference
end

it "does not attempt synchronization" do
expect { article.save }.to_not raise_error(TypeError)
end

it "sets the one side of the relation" do
article.preferences.should eq([ preference ])
end
end

context "when first setting by the relation itself" do

let!(:person) do
Expand Down

0 comments on commit 055e6ef

Please sign in to comment.