繁体   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