Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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 如何找到该字段或该字段在可接受值列表中的模型_Ruby On Rails_Postgresql_Activerecord_Rails Activerecord - Fatal编程技术网

Ruby on rails 如何找到该字段或该字段在可接受值列表中的模型

Ruby on rails 如何找到该字段或该字段在可接受值列表中的模型,ruby-on-rails,postgresql,activerecord,rails-activerecord,Ruby On Rails,Postgresql,Activerecord,Rails Activerecord,如何查找列表中开始节点或结束节点所在的关系 ids = ProcessingRun.last.nodes.pluck(:id) @rels = Relationship.where(:end_node_id => ids) + Relationship.where(:start_node_id => ids) 我尝试了很多关于或的变化 rels_in_id_array = Relationship.where("start_node_id in #{ids} OR end_node

如何查找列表中开始节点或结束节点所在的关系

ids = ProcessingRun.last.nodes.pluck(:id)
@rels = Relationship.where(:end_node_id => ids) + Relationship.where(:start_node_id => ids)
我尝试了很多关于或的变化

rels_in_id_array = Relationship.where("start_node_id in #{ids} OR end_node_id in#{ids}")
关系加载(0.9ms)从“关系”中选择“关系”。*其中(在[35752、35726、35728、35729、35731、35735、35736、35738、35742、35745、35750、35751、35723、35725、35739、35740、35749、35724、35722、35733、35734、35737、35741、35743、35732、35746、35747、35721、35731、35730、35747、35747、35744、35743、35748、35737、35734、35737、35737、35737、35737、35737、35733)或在节点id中结束[35752, 35726, 35728, 35729, 35731, 35735, 35736, 35738, 35742, 35745, 35750, 35751, 35723, 35725, 35739, 35740, 35749, 35724, 35722, 35733, 35734, 35737, 35741, 35743, 35732, 35746, 35747, 35721, 35730, 35727, 35744, 35748, 35753]) PG::SyntaxError:错误:在“[”处或附近出现语法错误 第1行:…“*”来自“关系”,其中(在[35752,35

它不起作用了


这就是为什么我想把两个数组加在一起。但事实证明它们是数组,而不是ActiveRecord关系,所以我不能用它们来处理AR关系。

也可以使用符号和散列进行插值,这在重复变量的情况下很有用:
。where(“start\u node\u id IN(:ids)或end\u node\u id IN(:ids)“,id:ids)
Relationship.where("start_node_id IN (?) OR end_node_id IN (?)", ids, ids)
Relationship.where('end_node_id IN (?) OR start_node_id IN (?)', ids, ids)