ActiveRecord是否支持where子句中的元組,假設底層數據庫呢?Ruby ActiveRecord和sql元組支持
產生的where子句看起來是這樣的:
where (name, address) in (('John', '123 Main St'))
我想:
Person.where({[:name, :address] => ['John', '123 Main St']})
,並沒有奏效。
ActiveRecord是否支持where子句中的元組,假設底層數據庫呢?Ruby ActiveRecord和sql元組支持
產生的where子句看起來是這樣的:
where (name, address) in (('John', '123 Main St'))
我想:
Person.where({[:name, :address] => ['John', '123 Main St']})
,並沒有奏效。
Person.where("(name, address) IN ((?))", ['John', '123 Main St'])
tupleArray = [['John', '123 Main St'],['Jane', '124 Main St']]
Person.where("(name, address) IN (#{(['(?)']*tupleArray.size).join(', ')})", *tupleArray)
這是一個黑客攻擊,並沒有資格被ActiveRecord「支持」。另外,黑客已經在[這裏]提到(https://groups.google.com/d/msg/rubyonrails-core/RnKkEwbcNCk/3AJz9UOy_d4J) – Kelvin
與一個元組的工作,但不能與多個元組。我嘗試過'[['John','123 Main St'],['Jane','456 Oak St']],但AR將每個嵌套數組轉換爲YAML。 – Kelvin