Knowing I want Magento assemble and execute the following query :

    `catalog_product_entity_media_gallery_value` AS `tGV`
INNER JOIN `catalog_product_entity_media_gallery` AS `tG` ON
    `tG` . value_id = value_id
    `tGV` . `position` = 2
        `tG` . `value` LIKE '%_pms_%'

I came to the following code :

$select = $connection
        ['tG' => $tableGallery],
        '`tG`.`value_id` = `tGV`.`value_id`',
        ['position' => new Expr('2')]
    ->where("`tG`.`value` LIKE '%_pms_master%'");

$update = $connection->updateFromSelect($select, ['tGV' => $tableGalleryValue]);


This code works but it is not obvious to understand and therefore to maintain. Question is : do you have any idea how to do better : simpler / cleaner / more understandable ?

  • $update is a string that is the SQL statement. I would just echo $update and copy the output as comment. – kiatng Jan 16 '18 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.