Guest User

Untitled

a guest
Dec 11th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Doctrine\Tests\ORM\Mapping;
  4.  
  5. use Doctrine\ORM\Mapping\ClassMetadata,
  6. Doctrine\ORM\Mapping\ClassMetadataInfo;
  7.  
  8. class User
  9. {
  10. protected $id;
  11.  
  12. protected $name;
  13.  
  14. protected $email;
  15.  
  16. protected $groups;
  17. }
  18.  
  19. $metadata = new ClassMetadata('Doctrine\Tests\ORM\Mapping\User');
  20.  
  21. $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
  22. $metadata->setPrimaryTable(array(
  23. 'name' => 'cms_users',
  24. ));
  25. $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
  26. $metadata->addNamedQuery(array(
  27. 'name' => 'all',
  28. 'query' => 'SELECT u FROM __CLASS__ u'
  29. ));
  30. $metadata->mapField(array(
  31. 'id' => true,
  32. 'fieldName' => 'id',
  33. 'type' => 'integer',
  34. 'columnName' => 'id',
  35. ));
  36. $metadata->mapField(array(
  37. 'fieldName' => 'name',
  38. 'type' => 'string',
  39. 'length' => 50,
  40. 'unique' => true,
  41. 'nullable' => true,
  42. 'columnName' => 'name',
  43. ));
  44. $metadata->mapField(array(
  45. 'fieldName' => 'email',
  46. 'type' => 'string',
  47. 'columnName' => 'user_email',
  48. 'columnDefinition' => 'CHAR(32) NOT NULL',
  49. ));
  50. $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
  51. $metadata->mapManyToMany(array(
  52. 'fieldName' => 'groups',
  53. 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group',
  54. 'cascade' =>
  55. array(
  56. 0 => 'remove',
  57. 1 => 'persist',
  58. 2 => 'refresh',
  59. 3 => 'merge',
  60. 4 => 'detach',
  61. ),
  62. 'mappedBy' => NULL,
  63. 'joinTable' =>
  64. array(
  65. 'name' => 'cms_users_groups',
  66. 'joinColumns' =>
  67. array(
  68. 0 =>
  69. array(
  70. 'name' => 'user_id',
  71. 'referencedColumnName' => 'id',
  72. 'unique' => false,
  73. 'nullable' => false,
  74. ),
  75. ),
  76. 'inverseJoinColumns' =>
  77. array(
  78. 0 =>
  79. array(
  80. 'name' => 'group_id',
  81. 'referencedColumnName' => 'id',
  82. 'columnDefinition' => 'INT NULL',
  83. ),
  84. ),
  85. ),
  86. 'orderBy' => NULL,
  87. ));
  88. $metadata->table['uniqueConstraints'] = array(
  89. 'search_idx' => array('columns' => array('name', 'user_email')),
  90. );
  91. $metadata->table['indexes'] = array(
  92. 'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
  93. );
  94. $metadata->setSequenceGeneratorDefinition(array(
  95. 'sequenceName' => 'tablename_seq',
  96. 'allocationSize' => 100,
  97. 'initialValue' => 1,
  98. ));
Add Comment
Please, Sign In to add comment