Created
August 1, 2011 22:48
-
-
Save jc00ke/1119175 to your computer and use it in GitHub Desktop.
Embedded document persisted w/o an id
This file contains hidden or 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
class Photo | |
include Mongoid::Document | |
embedded_in :listing | |
field :position, :type => Integer, :default => 0 | |
end |
This file contains hidden or 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
class Widget | |
include Mongoid::Document | |
embeds_many :photos | |
end |
This file contains hidden or 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
irb(main):002:0> w = Widget.find "4e371e3814c33c45d00002c2" | |
=> #<Widget _id: 4e371e3814c33c45d00002c2, serial_number: "001204484"> | |
irb(main):003:0> w.photos | |
=> [ | |
#<Photo _id: 4e371e4714c33c45da000203, position: 1>, | |
#<Photo _id: 4e371e4f14c33c45d00002c4, position: 4>, | |
#<Photo _id: 4e371e5114c33c45da000205, position: 5>, | |
#<Photo _id: 4e371e5314c33c45d00002c6, position: 6>, | |
#<Photo _id: 4e371ec414c33c45d00002c8, position: 8>, | |
#<Photo _id: 4e371ec714c33c45da000207, position: 9>, | |
#<Photo _id: , position: 0> | |
] | |
irb(main):004:0> l.photos[6] | |
=> #<Photo _id: , position: 0> | |
irb(main):005:0> l.photos[6].destroy | |
=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment