Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 与rails中的条件有一个多态关联_Ruby On Rails_Ruby On Rails 3_Polymorphic Associations_Model Associations - Fatal编程技术网

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}"