Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1242

Many to many relationship selects models that are not related

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Hi, here's a diff for the failing spec I wrote to demonstrate what is wrong:

      diff --git a/spec/functional/mongoid/relations/referenced/many_to_many_spec.rb b/spec/functional/mongoid/relations/referenced/many_to_many_spec.rb
      index b06920c..f2ea875 100644
      — a/spec/functional/mongoid/relations/referenced/many_to_many_spec.rb
      +++ b/spec/functional/mongoid/relations/referenced/many_to_many_spec.rb
      @@ -1582,6 +1582,22 @@ describe Mongoid::Relations::Referenced::ManyToMany do
      end
      end

      + describe "#where finder" do
      + let(:person) do
      + Person.create(:ssn => "123-45-6789")
      + end
      +
      + let(:account) do
      + UserAccount.create(:username => "chitchins", :email => 'chitchins@test.com')
      + end
      +
      + it "should not select model which is not related" do
      + person.user_accounts.count.should eql 0
      + account.people.count.should eql 0
      + person.user_accounts.where(:_id => account.id).count.should eql 0
      + end
      + end
      +
      describe "#max" do

      let(:person) do

      So, basically, person.user_accounts.where(:_id => account.id) or any other finder should not select anything except for when there's a relationship.

      If you could give me a hint for where to look, i'll try to fix it myself.

      Thank you.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ifesdjeen oleksandr petrov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: