Skip to content

Instantly share code, notes, and snippets.

@tazsingh
Created April 11, 2011 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tazsingh/913685 to your computer and use it in GitHub Desktop.
Save tazsingh/913685 to your computer and use it in GitHub Desktop.
Mongoid appends to 'embedded' criteria instead of 'selector' criteria
class Foo
include Mongoid::Document
references_many :bars
end
class Bar
include Mongoid::Document
referenced_in :foo
end
f = Foo.create
f.bars << [Bar.create, Bar.create, Bar.create]
b = Bar.scoped :foo_id => f.id
# Note this appends to the 'embedded' attribute instead of the 'selector' attribute
##<Mongoid::Criteria
# selector: {},
# options: {},
# class: Bar,
# embedded: {:foo_id=>BSON::ObjectId('4da31811031af40439000001')}>
b.to_a
# []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment