Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.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 ';在';在postgresql中查询两个显示相同结果的不同查询_Ruby On Rails_Postgresql - Fatal编程技术网

Ruby on rails ';在';在postgresql中查询两个显示相同结果的不同查询

Ruby on rails ';在';在postgresql中查询两个显示相同结果的不同查询,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我的活动记录关联关系如下 @tasks = #<ActiveRecord::AssociationRelation [#<Task id: 3130, title: "Commit to at least one small win today", content: "When I check-in on the app it lets me acknowledge m...",created_at: "2016-01-13 01:36:15", updated_at: "2016

我的活动记录关联关系如下

@tasks =  #<ActiveRecord::AssociationRelation [#<Task id: 3130, title: "Commit to at least one small win today", content: "When I check-in on the app it lets me acknowledge m...",created_at: "2016-01-13 01:36:15", updated_at: "2016-01-13 04:47:57", state: "active", #<Task id: 3131, title: "Purposefully walk 3 minutes ", content: "More than just my ordinary day, I choose 5 minutes ...", created_at: "2016-01-13 04:52:32", updated_at: "2016-01-13 04:56:22", state: "active", #<Task id: 3132, title: "1km Walk or Run by Sunday", content: "I pick a direction, start with a 10 minute warm up,...", created_at: "2016-01-13 04:56:05", updated_at: "2016-01-13 04:56:05", state: "active",#<Task id: 3249, title: "1km Walk or Run by Wednesday", content: "I pick a direction, start with a 10 minute warm up,...", created_at: "2016-01-24 23:23:34", updated_at: "2016-01-24 23:23:34", state: "active"]> 


@array = []

@tasks.each do |task|
if (condition)
  @array << task.id
end  

@tasks = @tasks.where.not('tasks.id in (?)',@array)

为什么这些查询在两个不同的条件下返回相同的值?

如果您的Rails版本是最新的,您应该切换到哈希表示法,它可以处理所有特殊情况,例如空数组:

@tasks = @tasks.where.not(id: @array)

如果您的Rails版本是最新的,您应该切换到哈希表示法,它可以处理所有特殊情况,例如空数组:

@tasks = @tasks.where.not(id: @array)