ActiveRecord: update for PostgreSQL with attachment

A line like this (split across multiple lines for readability):

ValueMapping
    .joins(:variation)
    .where(
        :mapper_id => 1,
        :variations => {:name => 'de'}
    )
    .update_all(:value => 'Beispiel')

      

creates the following SQL statement:

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'
)

      

But I would like to get more PostgreSQL specific queries:

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'
)

      

Is this possible with ActiveRecord?

+3


source to share





All Articles