Maarten
Maarten

Reputation: 63

Doctrine 2 - How can I add a CHECK .. IN constraint

How can I add a CHECK .. IN constraint, like in the code below, in Doctrine 2?

CREATE TABLE table_name (
    colum_name VARCHAR(1) 
    CHECK (column_name IN ('A','B','C'))
);

-- edit: I use annotations to define my entities

Upvotes: 6

Views: 3527

Answers (1)

Ocramius
Ocramius

Reputation: 25440

This is not supported by the ORM itself. You can define custom DDL to be used for those columns through your metadata driver. For instance, in the AnnotationDriver you can use /** @Column(type="string", columnDefinition="VARCHAR(1) CHECK (column_name IN ('A','B','C'))") */ as defined in the Annotations Reference. I would avoid it anyway and keep those checks on application level.

Upvotes: 6

Related Questions