在下面的Mongoid模型中,我如何別名belongs_to
關係字段?在Mongoid中別名引用關係字段
class Contact
field :nm, :as => :name, :type => String # field aliasing
embeds_one :address, :store_as => :ad # embedded document aliasing
belongs_to :account # referenced relation doesn't support store_as
end
我想帳戶ID存儲在一個名爲ac
而不是account_id
領域。
這並沒有解決我的問題。我想將帳戶字段稱爲「帳戶」而不是「ac」,因此需要別名功能。 –
您想要立即通過conact.ac和contact.account解決?請解釋。 –
Mongoid庫提供了一個用於別名字段名稱的功能。這在處理大型集合時非常有用。從本質上講,如果你看看我的問題中的第一個場景,我將名稱作爲'nm'存儲在集合中,但訪問/查詢它爲'name'。此功能適用於常規字段和嵌入式關聯。對於引用的關聯,沒有書面的方式來設置此選項。 –