Skip to content

Instantly share code, notes, and snippets.

@mariovisic
Created November 22, 2010 03:53
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 mariovisic/709494 to your computer and use it in GitHub Desktop.
Save mariovisic/709494 to your computer and use it in GitHub Desktop.
Mongoid find behaviour
form.id # => BSON::ObjectId('4ce9df0d4cfad1c62400001b')
form.messages.first.id # => BSON::ObjectId('4ce9e3d74cfad1cabd000006')
Form.find('4ce9df0d4cfad1c62400001b').to_s # => "#<Form:0x105673c60>"
Form.find('4ce9df0d4cfad1c624000010').to_s # Mongoid::Errors::DocumentNotFound: Document not found for class Form with id(s) 4ce9df0d4cfad1c624000010.
form.messages.find('4ce9e3d74cfad1cabd000006').to_s # => "#<Message:0x10527c170>"
form.messages.find('4ce9e3d74cfad1cabd000000').to_s # => ""
# find on a class throws an exception where as find on a collection returns nil for no results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment