Hi all,
After a couple of days, I've decided to post my issue here. I can`t use the
"translatable" extension of Doctrine, because my database is legacy and I
can't change it, so this is not an option for me. For an easier
understanding, I have simplified my objects name and structure to extreme.
SHEMA:
- Post (id)
- PostI18n (post_id, locale, content)
- Relation 1:n between Post and Category, properly implemented with
doctrine. All Post have a "FR" and a "EN" translations.
My query: $results = $em->createQuery('SELECT p, pi18n from Post p JOIN
p.translations pi18n WHERE pi18n.locale = 'EN'")->getResult($fetch_method)
*If fetch_method is Query::HYDRATE_ARRAY, absolutely no problem the output
is as expected:*
*array* *(size=7)*
0 =>
*array* *(size=6)*
'id' => int 14
'translations' =>
*array* *(size=1)*
0 =>
*array* *(size=2)*
'locale' => string 'FR' *(length=2)*
'content' => string 'This is the post with ID 14' *(length=6)*
1 =>
*array* *(size=6)*
'id' => int 15
'translations' =>
*array* *(size=1)*
0 =>
*array* *(size=2)*
'locale' => string 'FR' *(length=2)*
'content' => string 'This is the post with ID 15'
*(length=6)*
*If fetch_method is Query::HYDRATE_OBJECT, I have the following behavior:*
- But when I try to loop on posts, this is what happens:
- *Input *: foreach ($posts as $post) { echo
count($post->getTranslations()) . ";" }
- *Output* : 1;1
- *Input *: foreach ($posts as $post) { echo
$post->getTranslations()[0]->getContent() . ";" }
- *Output* : This is the post with ID 14;This is the post with ID 14
This is of course wrong, all my Post object are containing the PostI18n
instance linked to Post n° 14 ! Can someone help me to understand this
behavior, and help me to find a solution/workaround to continue to deal
with objects? Of course I still want Lazy loading, then no subqueries in my
foreach loop.
Many Thanks,
Damien THIESSON
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.