Created
November 22, 2010 03:53
-
-
Save mariovisic/709494 to your computer and use it in GitHub Desktop.
Mongoid find behaviour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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