4

In the InstallSchema.php, I would like to add an unique contraint on a combination of column.

In SQL, it would be done with this request:

ALTER TABLE `linked_cities` ADD UNIQUE `unique_index`(`vendor`, `zip`, `city`);

Is there a way to do that with the Magento ORM in order to avoid any further intervention on the database?

Regards

1 Answer 1

3

Problem solved: in the script, I directly executed the request:

$myRequest = "ALTER TABLE...";
$installer->getConnection()->query($myRequest );

EDIT: finally found how to do it with the Magento methods:

$myTable->addIndex(
            $installer->getIdxName($tableName, $arrayOfColumnsName),
            arrayOfColumnsName,
            ['type' => 'unique']
        );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.