像这样的行(为了便于阅读,分成多行):
ValueMapping
.joins(:variation)
.where(
:mapper_id => 1,
:variations => {:name => 'de'}
)
.update_all(:value => 'Beispiel')
产生以下 SQL 语句:
UPDATE value_mappings
SET value = 'Beispiel'
WHERE value_mappings.id IN (
SELECT value_mappings.id
FROM
value_mappings
INNER JOIN variations ON variations.id = value_mappings.variation_id
WHERE
value_mappings.mapper_id = 1
AND variations.name = 'de'
)
但我想获得更多特定于 PostgreSQL 的请求:
UPDATE value_mappings
SET value = 'Beispiel'
FROM
variations
WHERE
variations.id = value_mappings.variation_id
AND value_mappings.mapper_id = 1
AND variations.name = 'de'
)
ActiveRecord可以吗?