Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use DoctrineORMMapping as ORM;
- /**
- * @ORMEntity
- * @ORMTable(
- * name="parent"
- * )
- */
- class Parent
- {
- /**
- * @ORMId
- * @ORMColumn(name="parent_id", type="integer")
- * @ORMGeneratedValue
- */
- private $id;
- /**
- * @ORMOneToMany(targetEntity="Child", mappedBy="parent", cascade={"persist", "remove"})
- */
- private $children;
- // other fields, getters, setters, etc
- }
- use DoctrineORMMapping as ORM;
- /**
- * @ORMEntity
- * @ORMTable(
- * name="child",
- * uniqueConstraints={@ORMUniqueConstraint(name="parent_child_type", columns={"parent_id", "child_type"})}
- * )
- */
- class Child
- {
- /**
- * @ORMId
- * @ORMColumn(name="child_id", type="integer")
- * @ORMGeneratedValue
- */
- private $id;
- /**
- * @ORMManyToOne(targetEntity="Parent", inversedBy="children")
- * @ORMJoinColumn(name="parent_id", referencedColumnName="parent_id")
- */
- private $parent;
- /**
- * @ORMColumn(name="child_type", type="string", length=32)
- */
- private $type;
- // other fields, getters, setters, etc
- }
- # make sure the collection is valid, which forces validation of each Child
- ExampleMyBundleORMModelParent:
- properties:
- children:
- - Valid: ~
- # enforce uniqueness between the two fields
- ExampleMyBundleORMModelChild:
- constraints:
- - SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity:
- fields: [ parent, type ]
- message: You may only configure one child of each type per parent.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement