2013-12-09 63 views
0

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

然而,這似乎並沒有工作,這聽起來像conditions在Rails的棄用4

下面是我爲協會代碼:

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

有沒有辦法讓這個在Rails 4中工作?

+2

這應該與你在找什麼:http://stackoverflow.com/questions/16569994/deprecation-warning-when-using-has-many-through-uniq-in-導軌-4 – Severin

回答

0

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

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