1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Added tests for OneToMany associations and lazy collection to STI entity

This commit is contained in:
Alexander 2011-12-22 20:50:57 +01:00
parent 223c47069e
commit f49a4e9c40
4 changed files with 64 additions and 2 deletions

View file

@ -119,8 +119,9 @@ class OneToManyPersister extends AbstractCollectionPersister
: $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]]; : $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]];
} }
$filterTargetClass = $this->_em->getClassMetadata($targetClass->rootEntityName);
foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) {
if ($filterExpr = $filter->addFilterConstraint($targetClass, 't')) { if ($filterExpr = $filter->addFilterConstraint($filterTargetClass, 't')) {
$whereClauses[] = '(' . $filterExpr . ')'; $whereClauses[] = '(' . $filterExpr . ')';
} }
} }

View file

@ -21,7 +21,7 @@ abstract class CompanyContract
private $id; private $id;
/** /**
* @ManyToOne(targetEntity="CompanyEmployee") * @ManyToOne(targetEntity="CompanyEmployee", inversedBy="soldContracts")
*/ */
private $salesPerson; private $salesPerson;

View file

@ -28,6 +28,11 @@ class CompanyEmployee extends CompanyPerson
*/ */
public $contracts; public $contracts;
/**
* @OneToMany(targetEntity="CompanyFlexUltraContract", mappedBy="salesPerson", fetch="EXTRA_LAZY")
*/
public $soldContracts;
public function getSalary() { public function getSalary() {
return $this->salary; return $this->salary;
} }

View file

@ -667,6 +667,9 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
$contract1->addManager($manager2); $contract1->addManager($manager2);
$contract1->setSalesPerson($manager);
$contract2->setSalesPerson($manager);
$this->_em->persist($manager); $this->_em->persist($manager);
$this->_em->persist($manager2); $this->_em->persist($manager2);
$this->_em->persist($contract1); $this->_em->persist($contract1);
@ -804,6 +807,59 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertFalse($contract->managers->isInitialized()); $this->assertFalse($contract->managers->isInitialized());
$this->assertEquals(1, count($contract->managers->slice(0, 10))); $this->assertEquals(1, count($contract->managers->slice(0, 10)));
} }
public function testOneToMany_ExtraLazyCountWithFilterOnSTI()
{
$this->loadCompanySingleTableInheritanceFixtureData();
$manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId);
$this->assertFalse($manager->soldContracts->isInitialized());
$this->assertEquals(2, count($manager->soldContracts));
// Enable the filter
$this->useCompletedContractFilter();
$this->assertFalse($manager->soldContracts->isInitialized());
$this->assertEquals(1, count($manager->soldContracts));
}
public function testOneToMany_ExtraLazyContainsWithFilterOnSTI()
{
$this->loadCompanySingleTableInheritanceFixtureData();
$manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId);
$contract1 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->contractId1);
$contract2 = $this->_em->find('Doctrine\Tests\Models\Company\CompanyContract', $this->contractId2);
$this->assertFalse($manager->soldContracts->isInitialized());
$this->assertTrue($manager->soldContracts->contains($contract1));
$this->assertTrue($manager->soldContracts->contains($contract2));
// Enable the filter
$this->useCompletedContractFilter();
$this->assertFalse($manager->soldContracts->isInitialized());
$this->assertFalse($manager->soldContracts->contains($contract1));
$this->assertTrue($manager->soldContracts->contains($contract2));
}
public function testOneToMany_ExtraLazySliceWithFilterOnSTI()
{
$this->loadCompanySingleTableInheritanceFixtureData();
$manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $this->managerId);
$this->assertFalse($manager->soldContracts->isInitialized());
$this->assertEquals(2, count($manager->soldContracts->slice(0, 10)));
// Enable the filter
$this->useCompletedContractFilter();
$this->assertFalse($manager->soldContracts->isInitialized());
$this->assertEquals(1, count($manager->soldContracts->slice(0, 10)));
}
} }
class MySoftDeleteFilter extends SQLFilter class MySoftDeleteFilter extends SQLFilter