Skip to content

Commit

Permalink
Mongoid internal indexing for relational associations should happen i…
Browse files Browse the repository at this point in the history
…n background
  • Loading branch information
durran committed Jul 24, 2010
1 parent 8311109 commit cde72f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/mongoid/associations.rb
Expand Up @@ -177,7 +177,7 @@ def referenced_in(name, options = {}, &block)
opts = optionize(name, options, constraint(name, options, :in), &block)
associate(Associations::ReferencedIn, opts)
field(opts.foreign_key, :type => using_object_ids? ? BSON::ObjectID : String)
index(opts.foreign_key) if !embedded? && opts.index
index(opts.foreign_key, :background => true) if !embedded? && opts.index
set_callback(:save, :before) { |document| document.update_foreign_keys }
end

Expand Down Expand Up @@ -301,7 +301,7 @@ def reference_many(name, options, &block)
foreign_key = "#{name.to_s.singularize}_ids"
opts = optionize(name, options, constraint(name, options, :many_as_array), &block)
field(foreign_key, :type => Array, :default => [])
index(foreign_key) if opts.index
index(foreign_key, :background => true) if opts.index
associate(Associations::ReferencesManyAsArray, opts)
else
opts = optionize(name, options, constraint(name, options, :many), &block)
Expand Down
6 changes: 1 addition & 5 deletions spec/unit/mongoid/associations_spec.rb
Expand Up @@ -513,7 +513,7 @@
context "when index is set" do

it "puts an index on the foreign key" do
Game.expects(:index).with("person_id")
Game.expects(:index).with("person_id", :background => true)
Game.referenced_in :person, :index => true
end
end
Expand All @@ -534,7 +534,6 @@
Game.referenced_in :person
end
end

end

describe ".references_one" do
Expand All @@ -558,9 +557,7 @@
it "defines the method on the association" do
@person.game.extension.should == "Testing"
end

end

end

describe ".references_many" do
Expand All @@ -582,7 +579,6 @@
it "defines the method on the association" do
@person.posts.extension.should == "Testing"
end

end

context "with a stored_as option provided" do
Expand Down

0 comments on commit cde72f9

Please sign in to comment.