我如何能找到關係,其中起始節點或最終節點是列表的列表。如何找到模型,其中該領域或領域是可接受值
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)選擇 「關係」。* FROM 「關係」 WHERE(在start_node_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] OR end_node_id在[35752,35726,35728,35729,35731,35735,35736,35738,35742,35745,35750,35751,35723,35725,35739,35740,35749,35724, 35722,35734,35734,35737,35741,35743,35732,35746,35747 ,35721,35730,35727,35744,35748,35753]) PG ::語法錯誤:錯誤:語法錯誤或接近 「[」 LINE 1:「* FROM 」...的關係「 在WHERE(start_node_id [35752 ,35 ...
和它不工作....
所以這就是爲什麼我想我會加2列在一起。但事實證明它們是數組,而不是ActiveRecord關係,所以我不能對它們做與AR關係相關的事情。
太感謝你了! – Darby
您還可以使用符號和插值的哈希,這是非常有用的,你有反覆瓦爾:'。凡( 「start_node_id IN(:IDS),或在end_node_id(:IDS)」,IDS:IDS)' –