Ruby on rails 与rails中的条件有一个多态关联
我基本上想在下面提到的关联中添加一个条件Ruby on rails 与rails中的条件有一个多态关联,ruby-on-rails,ruby-on-rails-3,polymorphic-associations,model-associations,Ruby On Rails,Ruby On Rails 3,Polymorphic Associations,Model Associations,我基本上想在下面提到的关联中添加一个条件 class Group < ActiveRecord::Base has_one :post, :as => :owner, :dependent => :destroy belongs_to :head_post, :class_name => 'Post', :dependent => :destroy, :foreign_key => 'head_post_id' end 但这似乎不起作
class Group < ActiveRecord::Base
has_one :post, :as => :owner, :dependent => :destroy
belongs_to :head_post, :class_name => 'Post', :dependent => :destroy, :foreign_key => 'head_post_id'
end
但这似乎不起作用我不明白你的问题。您到底想做什么?@User089247它应该返回正确的post,group.post应该查询posts表(owner\u type和owner\u id),并检查group.head\u post\u id是否不等于fetched post(这意味着fetched post不应该是head\u post)
has_one :post, :as => :owner, :dependent => :destroy, :conditions => "posts.owner_id != #{self.head_post_id}"