Mongoid中class_name和inverse_class_name有什么区别?
答案 0 :(得分:1)
此代码将让您清楚地了解差异:
class Order
include Mongoid::Document
embeds_many :items
end
class Item
include Mongoid::Document
embedded_in :order
end
item = Item.new
order = Order.create({ items: [ item ] })
puts order.items.metadata.class_name
# => Item
puts order.items.metadata.inverse_class_name
# => Order
也就是说,class_name
是关系的referrer类,而inverse_class_name
是关系的裁判类。