-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DDC-3346] #1277 find one with eager loads is failing #1280
Merged
Ocramius
merged 22 commits into
doctrine:master
from
Ocramius:hotfix/#1277-find-one-with-eager-loads-is-failing
Jan 25, 2015
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e36c7b0
DDC-3346 failing test example
scaytrase 981cebb
Update test according to @Ocramius notes
scaytrase 4c62d3b
#1277 DDC-3346 DDC-3531 - moved resultsetmapping into the newly creat…
Ocramius 55930a3
#1277 DDC-3346 DDC-3531 - moved `selectColumnListSql` into the newly …
Ocramius b9f698c
#1277 DDC-3346 DDC-3531 - moved `selectJoinSql` into the newly create…
Ocramius 2a7f149
#1277 DDC-3346 DDC-3531 - moved `sqlAliasCounter` into the newly crea…
Ocramius ebdfab8
#1277 DDC-3346 DDC-3531 - moved `sqlTableAliases` into the newly crea…
Ocramius 8b9171c
#1277 DDC-3346 DDC-3531 - caching the currently in use persister context
Ocramius 23a0d9a
#1277 DDC-3346 DDC-3531 - switch persister context at runtime
Ocramius 67f60f2
#1277 DDC-3346 DDC-3531 - switching persister context at runtime, dep…
Ocramius a37fa97
#1277 DDC-3346 DDC-3531 - skipping joining of associations when limit…
Ocramius 1672448
#1277 DDC-3346 DDC-3531 - renaming persister context switch for clarity
Ocramius 157bf20
#1277 DDC-3346 DDC-3531 - additional tests for LIMIT and OFFSET repos…
Ocramius 6e3ad49
#1277 DDC-3346 DDC-3531 - constants over string references
Ocramius 16f447d
#1277 DDC-3346 DDC-3531 - correct usage of the model set (setUp/tearD…
Ocramius 36bc448
#1277 DDC-3346 DDC-3531 - refactoring test code for simplicity/readab…
Ocramius 04a271a
#1277 DDC-3346 DDC-3531 - refactoring test assets for readability
Ocramius 39a8941
#1277 DDC-3346 DDC-3531 - minor CS fixes/cleanups: avoiding setters
Ocramius 186c593
#1277 DDC-3346 DDC-3531 - proper bi-directional association setup
Ocramius dff3653
#1277 DDC-3346 DDC-3531 - enforcing `0` offset to avoid persisting mo…
Ocramius 97ea6a7
#1277 DDC-3346 - removing array-based persister context handling (be…
Ocramius d4b278c
#1277 DDC-3346 - removing leftover comments
Ocramius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 97 additions & 75 deletions
172
lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Large diffs are not rendered by default.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
lib/Doctrine/ORM/Persisters/Entity/CachedPersisterContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\ORM\Persisters\Entity; | ||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
use Doctrine\ORM\Query\ResultSetMapping; | ||
|
||
/** | ||
* A swappable persister context to use as a container for the current | ||
* generated query/resultSetMapping/type binding information. | ||
* | ||
* This class is a utility class to be used only by the persister API | ||
* | ||
* This object is highly mutable due to performance reasons. Same reasoning | ||
* behind its properties being public. | ||
* | ||
* @author Marco Pivetta <ocramius@gmail.com> | ||
*/ | ||
class CachedPersisterContext | ||
{ | ||
/** | ||
* Metadata object that describes the mapping of the mapped entity class. | ||
* | ||
* @var \Doctrine\ORM\Mapping\ClassMetadata | ||
*/ | ||
public $class; | ||
|
||
/** | ||
* ResultSetMapping that is used for all queries. Is generated lazily once per request. | ||
* | ||
* @var \Doctrine\ORM\Query\ResultSetMapping | ||
*/ | ||
public $rsm; | ||
|
||
/** | ||
* The SELECT column list SQL fragment used for querying entities by this persister. | ||
* This SQL fragment is only generated once per request, if at all. | ||
* | ||
* @var string|null | ||
*/ | ||
public $selectColumnListSql; | ||
|
||
/** | ||
* The JOIN SQL fragment used to eagerly load all many-to-one and one-to-one | ||
* associations configured as FETCH_EAGER, as well as all inverse one-to-one associations. | ||
* | ||
* @var string | ||
*/ | ||
public $selectJoinSql; | ||
|
||
/** | ||
* Counter for creating unique SQL table and column aliases. | ||
* | ||
* @var integer | ||
*/ | ||
public $sqlAliasCounter = 0; | ||
|
||
/** | ||
* Map from class names (FQCN) to the corresponding generated SQL table aliases. | ||
* | ||
* @var array | ||
*/ | ||
public $sqlTableAliases = array(); | ||
|
||
/** | ||
* Whether this persistent context is considering limit operations applied to the selection queries | ||
* | ||
* @var bool | ||
*/ | ||
public $handlesLimits; | ||
|
||
/** | ||
* @param ClassMetadata $class | ||
* @param ResultSetMapping $rsm | ||
* @param bool $handlesLimits | ||
*/ | ||
public function __construct( | ||
ClassMetadata $class, | ||
ResultSetMapping $rsm, | ||
$handlesLimits | ||
) { | ||
$this->class = $class; | ||
$this->rsm = $rsm; | ||
$this->handlesLimits = (bool) $handlesLimits; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC3346; | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="ddc3346_articles") | ||
*/ | ||
class DDC3346Article | ||
{ | ||
const CLASSNAME = __CLASS__; | ||
|
||
/** | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var DDC3346Author | ||
* | ||
* @ManyToOne(targetEntity="DDC3346Author", inversedBy="articles") | ||
* @JoinColumn(name="user_id", referencedColumnName="id") | ||
*/ | ||
public $user; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC3346; | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="ddc3346_users") | ||
*/ | ||
class DDC3346Author | ||
{ | ||
const CLASSNAME = __CLASS__; | ||
|
||
/** | ||
* @Id @Column(type="integer") | ||
* @GeneratedValue | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @Column(type="string", length=255, unique=true) | ||
*/ | ||
public $username; | ||
|
||
/** | ||
* @OneToMany(targetEntity="DDC3346Article", mappedBy="user", fetch="EAGER", cascade={"detach"}) | ||
*/ | ||
public $articles = array(); | ||
} |
77 changes: 77 additions & 0 deletions
77
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Tests\Models\DDC3346\DDC3346Article; | ||
use Doctrine\Tests\Models\DDC3346\DDC3346Author; | ||
|
||
/** | ||
* @group DDC-3346 | ||
*/ | ||
class DDC3346Test extends \Doctrine\Tests\OrmFunctionalTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->useModelSet('ddc3346'); | ||
|
||
parent::setUp(); | ||
|
||
$this->loadAuthorFixture(); | ||
} | ||
|
||
public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection() | ||
{ | ||
/* @var DDC3346Author $author */ | ||
$author = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findOneBy( | ||
array('username' => 'bwoogy') | ||
); | ||
|
||
$this->assertCount(2, $author->articles); | ||
} | ||
|
||
public function testFindLimitedWithEagerFetchWillNotHydrateLimitedCollection() | ||
{ | ||
/* @var DDC3346Author[] $authors */ | ||
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy( | ||
array('username' => 'bwoogy'), | ||
null, | ||
1 | ||
); | ||
|
||
$this->assertCount(1, $authors); | ||
$this->assertCount(2, $authors[0]->articles); | ||
} | ||
|
||
public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection() | ||
{ | ||
/* @var DDC3346Author[] $authors */ | ||
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy( | ||
array('username' => 'bwoogy'), | ||
null, | ||
null, | ||
0 // using an explicitly defined offset | ||
); | ||
|
||
$this->assertCount(1, $authors); | ||
$this->assertCount(2, $authors[0]->articles); | ||
} | ||
|
||
private function loadAuthorFixture() | ||
{ | ||
$user = new DDC3346Author(); | ||
$article1 = new DDC3346Article(); | ||
$article2 = new DDC3346Article(); | ||
|
||
$user->username = 'bwoogy'; | ||
$article1->user = $user; | ||
$article2->user = $user; | ||
$user->articles[] = $article1; | ||
$user->articles[] = $article2; | ||
|
||
$this->_em->persist($user); | ||
$this->_em->persist($article1); | ||
$this->_em->persist($article2); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will fail due to a DBAL bug