DDC1400Test.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\ORM\UnitOfWork;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. /**
  6. * @group DDC-1400
  7. */
  8. class DDC1400Test extends \Doctrine\Tests\OrmFunctionalTestCase
  9. {
  10. protected function setUp()
  11. {
  12. parent::setUp();
  13. try {
  14. $this->_schemaTool->createSchema(array(
  15. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400Article'),
  16. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400User'),
  17. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1400UserState'),
  18. ));
  19. } catch (\Exception $ignored) {
  20. }
  21. }
  22. public function testFailingCase()
  23. {
  24. $article = new DDC1400Article;
  25. $user1 = new DDC1400User;
  26. $user2 = new DDC1400User;
  27. $this->_em->persist($article);
  28. $this->_em->persist($user1);
  29. $this->_em->persist($user2);
  30. $this->_em->flush();
  31. $userState1 = new DDC1400UserState;
  32. $userState1->article = $article;
  33. $userState1->articleId = $article->id;
  34. $userState1->user = $user1;
  35. $userState1->userId = $user1->id;
  36. $userState2 = new DDC1400UserState;
  37. $userState2->article = $article;
  38. $userState2->articleId = $article->id;
  39. $userState2->user = $user2;
  40. $userState2->userId = $user2->id;
  41. $this->_em->persist($userState1);
  42. $this->_em->persist($userState2);
  43. $this->_em->flush();
  44. $this->_em->clear();
  45. $user1 = $this->_em->getReference(__NAMESPACE__.'\DDC1400User', $user1->id);
  46. $q = $this->_em->createQuery("SELECT a, s FROM ".__NAMESPACE__."\DDC1400Article a JOIN a.userStates s WITH s.user = :activeUser");
  47. $q->setParameter('activeUser', $user1);
  48. $articles = $q->getResult();
  49. $this->_em->flush();
  50. }
  51. }
  52. /**
  53. * @Entity
  54. */
  55. class DDC1400Article
  56. {
  57. /**
  58. * @Id
  59. * @Column(type="integer")
  60. * @GeneratedValue
  61. */
  62. public $id;
  63. /**
  64. * @OneToMany(targetEntity="DDC1400UserState", mappedBy="article", indexBy="userId", fetch="EXTRA_LAZY")
  65. */
  66. public $userStates;
  67. }
  68. /**
  69. * @Entity
  70. */
  71. class DDC1400User
  72. {
  73. /**
  74. * @Id
  75. * @Column(type="integer")
  76. * @GeneratedValue
  77. */
  78. public $id;
  79. /**
  80. * @OneToMany(targetEntity="DDC1400UserState", mappedBy="user", indexBy="articleId", fetch="EXTRA_LAZY")
  81. */
  82. public $userStates;
  83. }
  84. /**
  85. * @Entity
  86. */
  87. class DDC1400UserState
  88. {
  89. /**
  90. * @Id
  91. * @ManyToOne(targetEntity="DDC1400Article", inversedBy="userStates")
  92. */
  93. public $article;
  94. /**
  95. * @Id
  96. * @ManyToOne(targetEntity="DDC1400User", inversedBy="userStates")
  97. */
  98. public $user;
  99. /**
  100. * @Column(name="user_id", type="integer")
  101. */
  102. public $userId;
  103. /**
  104. * @Column(name="article_id", type="integer")
  105. */
  106. public $articleId;
  107. }