Details
Description
Annotations:
<?php
/** @Entity */
class Customer
{
/**
* @Id @Column(name="id", type="integer")
*/
private $customerId;
/**
* @OneToOne(targetEntity="Cart", mappedBy="customer")
*/
private $cart;
}
/** @Entity */
class Cart
{
/**
* @Id @Column(name="id", type="integer", nullable=false)
*/
private $cartId;
/**
* Shouldn't unique=true be setting a UNIQUE index on customer_id ??
*
* @OneToOne(targetEntity="Customer", inversedBy="cart")
* @JoinColumn(name="customer_id", referencedColumnName="id", nullable=false, unique=true)
*/
private $customer;
}
Resulting schema (MySQL), generated with orm:schema-tool:create in CLI:
CREATE TABLE `customer` ( `id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cart` ( `id` int(11) NOT NULL, `customer_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `customer_id` (`customer_id`), /* this should be UNIQUE KEY */ CONSTRAINT `cart_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
I think the key on customer_id in the cart should be generating a UNIQUE KEY by definition on a @OneToOne, with or without the unique= param in the annotation, right?
I've tested this with and without the unique=true param and in both cases it does not generate a UNIQUE key constraint.
Issue Links
- depends on
-
DDC-626
Remove Association Classes
-
Verified, however i cannot fix this know, we need another internal refactoring before this can be done.