Ruby ActiveRecord 和 sql 元组支持 [英] Ruby ActiveRecord and sql tuple support
本文介绍了Ruby ActiveRecord 和 sql 元组支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设底层数据库支持,ActiveRecord 是否支持 where 子句中的元组?
Does ActiveRecord support tuples in the where clause, assuming the underlying database does?
生成的 where 子句类似于:
The resulting where clause would look something like:
where (name, address) in (('John', '123 Main St'))
我试过了:
Person.where({[:name, :address] => ['John', '123 Main St']})
它没有用.
推荐答案
tupleArray = [['John', '123 Main St'],['Jane', '124 Main St']]
Person.where("(name, address) IN (#{(['(?)']*tupleArray.size).join(', ')})", *tupleArray)
这篇关于Ruby ActiveRecord 和 sql 元组支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文