Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. use DoctrineORMMapping as ORM;
  2.  
  3. /**
  4. * @ORMEntity
  5. * @ORMTable(
  6. * name="parent"
  7. * )
  8. */
  9. class Parent
  10. {
  11. /**
  12. * @ORMId
  13. * @ORMColumn(name="parent_id", type="integer")
  14. * @ORMGeneratedValue
  15. */
  16. private $id;
  17.  
  18. /**
  19. * @ORMOneToMany(targetEntity="Child", mappedBy="parent", cascade={"persist", "remove"})
  20. */
  21. private $children;
  22.  
  23. // other fields, getters, setters, etc
  24.  
  25. }
  26.  
  27. use DoctrineORMMapping as ORM;
  28.  
  29. /**
  30. * @ORMEntity
  31. * @ORMTable(
  32. * name="child",
  33. * uniqueConstraints={@ORMUniqueConstraint(name="parent_child_type", columns={"parent_id", "child_type"})}
  34. * )
  35. */
  36. class Child
  37. {
  38. /**
  39. * @ORMId
  40. * @ORMColumn(name="child_id", type="integer")
  41. * @ORMGeneratedValue
  42. */
  43. private $id;
  44.  
  45. /**
  46. * @ORMManyToOne(targetEntity="Parent", inversedBy="children")
  47. * @ORMJoinColumn(name="parent_id", referencedColumnName="parent_id")
  48. */
  49. private $parent;
  50.  
  51. /**
  52. * @ORMColumn(name="child_type", type="string", length=32)
  53. */
  54. private $type;
  55.  
  56. // other fields, getters, setters, etc
  57.  
  58. }
  59.  
  60. # make sure the collection is valid, which forces validation of each Child
  61. ExampleMyBundleORMModelParent:
  62. properties:
  63. children:
  64. - Valid: ~
  65.  
  66. # enforce uniqueness between the two fields
  67. ExampleMyBundleORMModelChild:
  68. constraints:
  69. - SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity:
  70. fields: [ parent, type ]
  71. message: You may only configure one child of each type per parent.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement