Doctrine: select query to refresh hydrated entity join?
A query load and hydrate a main entity with it's joined entities, which are filtered.
Same query with a different filtering did not update the joined entities.
Some data:
Tiers:
| id | name |
| 1 | alpha |
| 2 | beta |
Container:
| id | tiers_id | category |
| 10 | 1 | A |
| 20 | 1 | A |
| 30 | 1 | B |
| 40 | 1 | B |
Execute 2 queries to get some tiers with theirs containers joined, category A first, then category B:
$dql = "select t, c
from Tiers t
join t.containers c
where t.id in (?1) and c.category = (?2)";
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'A')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // tiers 1 with containers 10 and 20, that's fine !
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'B')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // BAD HERE: still get containers 10 and 20, looking for containers 30 and 40.
After the 2nd query, tiers 1 preserve its containers loaded during first query. That's not what is expected.
So is there a way to get the containers 30 and 40 after 2nd query ?
Maybe a kind of "reset/detach" the containers of tiers entities after the first query ?
Or anything else...
Mutiple select in queries are used to hydrate tiers with required containers joined.
'getContainers' method gives the expected containers from each tiers.
And cost to BDD is only 1 SQL query, whatever the quantity of tiers searched.
I suppose tiers cannot be detach/reload because they are updated before, between and after the queries, it throw this kind of exception when flushing:
Uncaught Exception: Multiple non-persisted new entities were found through the given association graph
* A new entity was found through the relationship 'XXX' that was not configured to cascade persist operations for entity: XXXEntityTiers@00000000257b87500000000018499b62.
symfony doctrine-orm
add a comment |
A query load and hydrate a main entity with it's joined entities, which are filtered.
Same query with a different filtering did not update the joined entities.
Some data:
Tiers:
| id | name |
| 1 | alpha |
| 2 | beta |
Container:
| id | tiers_id | category |
| 10 | 1 | A |
| 20 | 1 | A |
| 30 | 1 | B |
| 40 | 1 | B |
Execute 2 queries to get some tiers with theirs containers joined, category A first, then category B:
$dql = "select t, c
from Tiers t
join t.containers c
where t.id in (?1) and c.category = (?2)";
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'A')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // tiers 1 with containers 10 and 20, that's fine !
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'B')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // BAD HERE: still get containers 10 and 20, looking for containers 30 and 40.
After the 2nd query, tiers 1 preserve its containers loaded during first query. That's not what is expected.
So is there a way to get the containers 30 and 40 after 2nd query ?
Maybe a kind of "reset/detach" the containers of tiers entities after the first query ?
Or anything else...
Mutiple select in queries are used to hydrate tiers with required containers joined.
'getContainers' method gives the expected containers from each tiers.
And cost to BDD is only 1 SQL query, whatever the quantity of tiers searched.
I suppose tiers cannot be detach/reload because they are updated before, between and after the queries, it throw this kind of exception when flushing:
Uncaught Exception: Multiple non-persisted new entities were found through the given association graph
* A new entity was found through the relationship 'XXX' that was not configured to cascade persist operations for entity: XXXEntityTiers@00000000257b87500000000018499b62.
symfony doctrine-orm
1
stackoverflow.com/questions/48152609/… This could be the solution
– Jannes Botis
Dec 15 '18 at 14:01
add a comment |
A query load and hydrate a main entity with it's joined entities, which are filtered.
Same query with a different filtering did not update the joined entities.
Some data:
Tiers:
| id | name |
| 1 | alpha |
| 2 | beta |
Container:
| id | tiers_id | category |
| 10 | 1 | A |
| 20 | 1 | A |
| 30 | 1 | B |
| 40 | 1 | B |
Execute 2 queries to get some tiers with theirs containers joined, category A first, then category B:
$dql = "select t, c
from Tiers t
join t.containers c
where t.id in (?1) and c.category = (?2)";
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'A')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // tiers 1 with containers 10 and 20, that's fine !
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'B')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // BAD HERE: still get containers 10 and 20, looking for containers 30 and 40.
After the 2nd query, tiers 1 preserve its containers loaded during first query. That's not what is expected.
So is there a way to get the containers 30 and 40 after 2nd query ?
Maybe a kind of "reset/detach" the containers of tiers entities after the first query ?
Or anything else...
Mutiple select in queries are used to hydrate tiers with required containers joined.
'getContainers' method gives the expected containers from each tiers.
And cost to BDD is only 1 SQL query, whatever the quantity of tiers searched.
I suppose tiers cannot be detach/reload because they are updated before, between and after the queries, it throw this kind of exception when flushing:
Uncaught Exception: Multiple non-persisted new entities were found through the given association graph
* A new entity was found through the relationship 'XXX' that was not configured to cascade persist operations for entity: XXXEntityTiers@00000000257b87500000000018499b62.
symfony doctrine-orm
A query load and hydrate a main entity with it's joined entities, which are filtered.
Same query with a different filtering did not update the joined entities.
Some data:
Tiers:
| id | name |
| 1 | alpha |
| 2 | beta |
Container:
| id | tiers_id | category |
| 10 | 1 | A |
| 20 | 1 | A |
| 30 | 1 | B |
| 40 | 1 | B |
Execute 2 queries to get some tiers with theirs containers joined, category A first, then category B:
$dql = "select t, c
from Tiers t
join t.containers c
where t.id in (?1) and c.category = (?2)";
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'A')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // tiers 1 with containers 10 and 20, that's fine !
$result = $em->createQuery($dql)
->setParameter(1, array(1))
->setParameter(2, 'B')
->getResult();
$tiers = $result[0];
$containers = $tiers->getContainers(); // BAD HERE: still get containers 10 and 20, looking for containers 30 and 40.
After the 2nd query, tiers 1 preserve its containers loaded during first query. That's not what is expected.
So is there a way to get the containers 30 and 40 after 2nd query ?
Maybe a kind of "reset/detach" the containers of tiers entities after the first query ?
Or anything else...
Mutiple select in queries are used to hydrate tiers with required containers joined.
'getContainers' method gives the expected containers from each tiers.
And cost to BDD is only 1 SQL query, whatever the quantity of tiers searched.
I suppose tiers cannot be detach/reload because they are updated before, between and after the queries, it throw this kind of exception when flushing:
Uncaught Exception: Multiple non-persisted new entities were found through the given association graph
* A new entity was found through the relationship 'XXX' that was not configured to cascade persist operations for entity: XXXEntityTiers@00000000257b87500000000018499b62.
symfony doctrine-orm
symfony doctrine-orm
edited Nov 21 '18 at 8:43
Guillaume
asked Nov 20 '18 at 15:26
GuillaumeGuillaume
586
586
1
stackoverflow.com/questions/48152609/… This could be the solution
– Jannes Botis
Dec 15 '18 at 14:01
add a comment |
1
stackoverflow.com/questions/48152609/… This could be the solution
– Jannes Botis
Dec 15 '18 at 14:01
1
1
stackoverflow.com/questions/48152609/… This could be the solution
– Jannes Botis
Dec 15 '18 at 14:01
stackoverflow.com/questions/48152609/… This could be the solution
– Jannes Botis
Dec 15 '18 at 14:01
add a comment |
1 Answer
1
active
oldest
votes
Reset the tiers's containers before 2nd query:
foreach($result as $tiers)
$tiers->nullContainers();
Add method to EntityTiers:
public function nullContainers()
{
this->containers = null;
}
Then the 2nd query "refresh" tiers's containers.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396266%2fdoctrine-select-query-to-refresh-hydrated-entity-join%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Reset the tiers's containers before 2nd query:
foreach($result as $tiers)
$tiers->nullContainers();
Add method to EntityTiers:
public function nullContainers()
{
this->containers = null;
}
Then the 2nd query "refresh" tiers's containers.
add a comment |
Reset the tiers's containers before 2nd query:
foreach($result as $tiers)
$tiers->nullContainers();
Add method to EntityTiers:
public function nullContainers()
{
this->containers = null;
}
Then the 2nd query "refresh" tiers's containers.
add a comment |
Reset the tiers's containers before 2nd query:
foreach($result as $tiers)
$tiers->nullContainers();
Add method to EntityTiers:
public function nullContainers()
{
this->containers = null;
}
Then the 2nd query "refresh" tiers's containers.
Reset the tiers's containers before 2nd query:
foreach($result as $tiers)
$tiers->nullContainers();
Add method to EntityTiers:
public function nullContainers()
{
this->containers = null;
}
Then the 2nd query "refresh" tiers's containers.
answered Nov 21 '18 at 9:42
GuillaumeGuillaume
586
586
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53396266%2fdoctrine-select-query-to-refresh-hydrated-entity-join%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
stackoverflow.com/questions/48152609/… This could be the solution
– Jannes Botis
Dec 15 '18 at 14:01