bra*_*rad 7 activerecord ruby-on-rails has-many-through ruby-on-rails-3
我在建立一个has_many :through有条件的协会时遇到了问题.我有这个型号:
class Contact < AR
has_many :group_contacts
has_many :groups, :through => :group_contacts, :conditions => {:groups => {:published => true}}
end
Run Code Online (Sandbox Code Playgroud)
当我尝试从联系人实例化一个组时,会出现问题.使用上面的语法,我收到一个错误:
contact.groups.build
=> ActiveRecord::UnknownAttributeError: unknown attribute: groups
Run Code Online (Sandbox Code Playgroud)
但是,当我使用以下语法时,它可以工作:
has_many :groups, :through => :group_contacts, :conditions => ['groups.published = ?', true]
contact.groups.build
=> #<Group id: nil, name: nil, description: nil, created_at: nil, updated_at: nil, published: true>
Run Code Online (Sandbox Code Playgroud)
我在这个问题中看到了对确切问题的引用.据说将为此错误提交一张票(返回前3版本).我找不到任何东西rails 3.0.x.
我正在使用3.0.8.有没有人发现这个问题?
进一步说明:
我还发现,当我建立群组时,它实际上忽略了我在构建时的关联条件.我上面构建的唯一原因published => true是因为它是db中的默认值.
这似乎是一种回归,任何人都可以验证这一点吗?
has_many :groups, :through => :group_contacts, :conditions => {:published => true}
Run Code Online (Sandbox Code Playgroud)
要么
has_many :groups, :through => :group_contacts, :conditions => {"groups.published" => true}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8984 次 |
| 最近记录: |