簡體   English   中英

Rails 4模型關聯條件

[英]Rails 4 model associations conditions

我有一個與條件具有多態關聯的模型。

但是,這似乎不起作用,聽起來像在Rails 4中棄用了conditions

以下是我的關聯代碼:

has_one :top_background, :class_name => 'UploadedFile', as: :imageable,
            :conditions => { :imageable_type => 'venue_top_background' }, dependent: :destroy

有沒有辦法使它在Rails 4中工作?

在Rails 4中,條件是通過作用域塊作為has_one的第二個參數來實現的。 例如:

has_one :top_background, ->{where(imageable_type: 'venue_top_background')}, :class_name => 'UploadedFile', as: :imageable, dependent: :destroy

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM