与rails中的条件有一个多态关联

时间:2014-11-04 07:40:52

标签: 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

在帖子表中,我有两个记录,每个组是post和head_post,我使用组中的字段来区分这两个记录&#39; head_post_id&#39;

这样的东西
  has_one :post, :as => :owner, :dependent => :destroy, :conditions => "posts.owner_id != #{self.head_post_id}"  

但这似乎不起作用

0 个答案:

没有答案