[英]activerecord3 IN statement with array
This must be super basic, but I just can't figure it out. 这必须是超基本的,但是我无法弄清楚。 I want to select from a table with lots of tag names all the tags who aren't part of the array 'tagnames'. 我想从具有很多标签名的表中选择所有不属于数组“标签名”的标签。 I tried: 我试过了:
Tag.where(
"name != ?", tagnames
)
gives me "Operand should contain 1 column(s)" 给我“操作数应包含1列”
Tag.where(
"name NOT IN ?", tagnames
)
gives me a SQL error 给我一个SQL错误
I know how to get all entries with the names of tagnames: 我知道如何获取所有带有标记名的条目:
Tag.where(
:name => tagnames
)
just not how to say this inverse... Many thanks for any help! 只是不怎么说这个逆数...非常感谢您的帮助!
I think you just need to put the brackets round the ?
我认为您只需要将方括号括起来?
in your "name NOT IN ?"
在您的"name NOT IN ?"
ie "name NOT IN (?)"
. 即"name NOT IN (?)"
。 I expect that is the cause of your SQL error. 我希望这是您的SQL错误的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.