0

如何將舊的Rails has_many與條件轉換爲new - >語法?Converting Rails 4 has_many

這裏是的has_many:

has_many assets_name.to_sym, through: :associated_assets, 
    conditions: { assets: { type: asset_subclass_name } }, 
    source: asset_subclass_name.underscore 

回答

2

該過程的條件塊轉換成內部條件的有效軌道4的 - > {}。條件需要成爲has_many的第二個參數。

has_many assets_name.to_sym, -> { where(type: asset_subclass_name)}, 
    through: :associated_assets, 
    source: asset_subclass_name.underscore