Skip to content

Commit

Permalink
Fix SQL statement in add-complex-data-to-existing-entities.md (#1578)
Browse files Browse the repository at this point in the history
* Fix SQL statement in add-complex-data-to-existing-entities.md

Fixes #1577

* Add Unique Constraint for a one-to-one relation

I have used a Unique constraint for this, its also possible to achieve this by removing the id and making the combination of product_id and product_version_id the primary key

---------

Co-authored-by: Micha Hobert <[email protected]>
  • Loading branch information
Skunkynator and Isengo1989 authored Dec 10, 2024
1 parent 24c0962 commit 6884fa6
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ CREATE TABLE IF NOT EXISTS `swag_example_extension` (
`created_at` DATETIME(3) NOT NULL,
`updated_at` DATETIME(3) NULL,
PRIMARY KEY (`id`),
KEY `fk.swag_example_extension.product_id` (`product_id`),
CONSTRAINT `fk.swag_example_extension.product_id` FOREIGN KEY (`product_id`, `product_version_id`) REFERENCES `product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
CONSTRAINT `unique.swag_example_extension.product` UNIQUE (`product_id`, `product_version_id`),
CONSTRAINT `fk.swag_example_extension.product_id` FOREIGN KEY (`product_id`, `product_version_id`) REFERENCES `product` (`id`, `version_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL;
$connection->executeStatement($sql);
Expand Down

0 comments on commit 6884fa6

Please sign in to comment.