मैं उपयोगकर्ता मॉडल का अनुसरण किया है में, श्रेणी मॉडल, एम्बेड करता हैMongoDB - एक नया दस्तावेज़ बनाने एक एम्बेडेड सरणी
class User
include Mongoid::Document
include BCrypt
field :email, :type => String
field :password_hash, :type => String
field :password_salt, :type => String
embeds_many :categories
embeds_many :transactions
....
end
मेरा प्रश्न, मैं सिर्फ पाया जाता है कि अगर मैं कोड का उपयोग करें:
me = User.where("some conditions")
me.categories << Category.new(:name => "party")
सब कुछ ठीक काम करता है, लेकिन अगर मैं .create विधि का उपयोग करें:
me = User.where("some conditions")
me.categories << Category.create(:name => "party")
मैं एक अपवाद मिल जाएगा:
undefined method `new?' for nil:NilClass
कोई भी जानता है कि वह क्यों है? और mongoid.org http://mongoid.org/docs/persistence/standard.html से, मैं इसे देख सकता था। नया और .create वास्तव में एक ही mongo आदेश उत्पन्न करता है।
आवश्यकताओं मदद, धन्यवाद :)
पूरी तरह से समझते हैं बहुत स्पष्ट। – larryzhao