Of het nu de beste praktijk is of niet, is een zeer discutabel onderwerp. U moet bijvoorbeeld rekening houden met de limiet voor de objectgrootte (momenteel 4 MB, maar zal binnenkort toenemen).
wat betreft uw vraag:ik stel voor dat u
. wijzigt embeds_many :replies, :class_name => 'Message'
embedded_in :message, :inverse_of => :replies
naar
embeds_many :replies, :class_name => 'Message'
referenced_in :message
En u zult beide verbindingen ook handmatig moeten specificeren (dat zou geen probleem moeten zijn, aangezien ze waarschijnlijk toch onveranderlijk zijn).
irb(main):002:0> msg1 = Message.new :subject => 'new question'
=> #<Message _id: 4cc7699f457601d7e8000001, created_at: nil, body: nil, updated_at: nil, subject: "new question", read_at: nil, sender_deleted: false, message_id: nil, recipient_deleted: false>
irb(main):003:0> msg2 = Message.new :subject => 'first comment'
=> #<Message _id: 4cc769b6457601d7e8000002, created_at: nil, body: nil, updated_at: nil, subject: "first comment", read_at: nil, sender_deleted: false, message_id: nil, recipient_deleted: false>
irb(main):005:0> msg2.message = msg1
=> #<Message _id: 4cc7699f457601d7e8000001, created_at: nil, body: nil, updated_at: nil, subject: "new question", read_at: nil, sender_deleted: false, message_id: nil, recipient_deleted: false>
irb(main):007:0> msg1.replies << msg2
=> [#<Message _id: 4cc769b6457601d7e8000002, created_at: nil, body: nil, updated_at: nil, subject: "first comment", read_at: nil, sender_deleted: false, message_id: BSON::ObjectId('4cc7699f457601d7e8000001'), recipient_deleted: false>]
irb(main):008:0> msg1.save
=> true