spinoza
spinoza

Reputation: 206

Symfony2 @UniqueEntity constraint on 2 foreign keys not working

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@UniqueEntity({"store_id","user_id"})

php app/console doctrine:schema:update --force

Nothing to update - your database is already in sync with the current entity metadata.

I tried to delete and create the table again, there is no unique key created.

Upvotes: 1

Views: 649

Answers (1)

jcroll
jcroll

Reputation: 7165

Try:

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

@UniqueEntity(fields={"store_id","user_id"})

Bear in mind the validator has nothing to do with the underlying database schema, it just validates the current state of the object. If you want to create a custom unique index consult the @UniqueConstraint annotation in doctrine:

/**
 * @Entity
 * @Table(name="ecommerce_products",uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"store_id", "user_id"})})
 */
class ECommerceProduct
{
}

Upvotes: 1

Related Questions