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

Don't hit db when relation key field is blank

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

      E.g:

      class Foo; include Mongoid::Document; has_and_belongs_to_many :bars;end
      class Bar; include Mongoid::Document; end
      f = Foo.create!
      f.bar_ids
       => []
      f.bars
       => []
      

      All good, but in the log for the last command I see:

      MONGODB blah_development['bars'].find({:_id=>{"$in"=>[]}})
      

      Could just save the db hit by noticing bar_ids is empty..?

            Assignee:
            Unassigned Unassigned
            Reporter:
            bensymonds Ben Symonds
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: