Added tests for OneToMany associations and lazy collection to STI entity
This commit is contained in:
parent
223c47069e
commit
f49a4e9c40
@ -119,8 +119,9 @@ class OneToManyPersister extends AbstractCollectionPersister
|
||||
: $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]];
|
||||
}
|
||||
|
||||
$filterTargetClass = $this->_em->getClassMetadata($targetClass->rootEntityName);
|
||||
foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) {
|
||||
if ($filterExpr = $filter->addFilterConstraint($targetClass, 't')) {
|
||||
if ($filterExpr = $filter->addFilterConstraint($filterTargetClass, 't')) {
|
||||
$whereClauses[] = '(' . $filterExpr . ')';
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ abstract class CompanyContract
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="CompanyEmployee")
|
||||
* @ManyToOne(targetEntity="CompanyEmployee", inversedBy="soldContracts")
|
||||
*/
|
||||
private $salesPerson;
|
||||
|
||||
|
@ -28,6 +28,11 @@ class CompanyEmployee extends CompanyPerson
|
||||
*/
|
||||
public $contracts;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="CompanyFlexUltraContract", mappedBy="salesPerson", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
public $soldContracts;
|
||||
|
||||
public function getSalary() {
|
||||
return $this->salary;
|
||||
}
|
||||
|
@ -667,6 +667,9 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$contract1->addManager($manager2);
|
||||
|
||||
$contract1->setSalesPerson($manager);
|
||||
$contract2->setSalesPerson($manager);
|
||||
|
||||
$this->_em->persist($manager);
|
||||
$this->_em->persist($manager2);
|
||||
$this->_em->persist($contract1);
|
||||
@ -804,6 +807,59 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertFalse($contract->managers->isInitialized());
|
||||
$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
|
||||
|
Loading…
x
Reference in New Issue
Block a user