Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
LEFT JOIN / joined results not handled
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
James Tucker  
View profile   Translate to Translated (View Original)
 More options 8 July, 19:18
From: James Tucker <tenlet...@gmail.com>
Date: Wed, 8 Jul 2009 11:18:05 -0700 (PDT)
Local: Wed 8 July 2009 19:18
Subject: LEFT JOIN / joined results not handled
Hello there,

i encountered a problem, when using a left join command in a query.
Basically, what happened is that my joined results were not appearing
in the final results of the query. After carefully testing the
validity of the actual query (by testing the query to mysql directly)
i realized that the problem can not originate from mysql as such.

A few details:

Model A:
Consists of an (primary key) 'id' of type string, length 16
and a few other fields, most importantly for this example a field
'code' (string/10)

Model B:
Has a field 'mandantPath' that is related to model A (field id)
through a hasOne() relation.

#code
$this->hasOne('mandant_db_node as mandant', array
('local'=>'mandantPath','foreign'=>'id'));

#here is my query

        $l=Doctrine_Query::create()
                         ->select('*,p.code')
                         ->from('contact_db_customer cc')
                         ->leftJoin('cc.mandant p')
                         ->where($w)
                         ->offset($request['startindex']+0)
                         ->limit($request['rows']+0)
                         ->orderBy($order)
                         ->execute(array());

Now, if i call this the way i do (above), i get the basic results
(fields), but not the joined ones. If i get the SQL query generated by
Doctrine, and use it directly, it works just fine and it returns the
'code' field as it should.

However, when i add type Doctrine::HYDRATE_ARRAY to the execute
command, i get the correct results, but of course encapsuled.. so that
i have to loop/parse through the result and set the values according
to my demands.

Pretty frustrating - while i am certain that the problem is very basic
and i just lack the knowledge of a proper solution. Hopefully someone
in here knows what i am dealing with - specifically, what it is that i
am doing wrong.

Kind regards, James


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Wage  
View profile   Translate to Translated (View Original)
 More options 8 July, 19:20
From: Jonathan Wage <jonw...@gmail.com>
Date: Wed, 8 Jul 2009 13:20:00 -0500
Subject: Re: [doctrine-user] LEFT JOIN / joined results not handled

I think it is because you are not selecting enough data from the cc alias.
Try just changing it to a wide open select by removing the select() line.

- Jon

--
Jonathan H. Wage (+1 415 992 5468)
Open Source Software Developer & Evangelist
sensiolabs.com | jwage.com | doctrine-project.org | symfony-project.org

You can contact Jonathan about Doctrine, Symfony and Open-Source or for
training, consulting, application development, or business related questions
at jonathan.w...@sensio.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 9 July, 10:19
From: James Tucker <tenlet...@gmail.com>
Date: Thu, 9 Jul 2009 02:19:13 -0700 (PDT)
Local: Thurs 9 July 2009 10:19
Subject: Re: LEFT JOIN / joined results not handled
Thank you for the hint,

i tried it, without select, but the results were exactly the same.

Does anyone know what is going wrong here?

On 8 Jul., 20:20, Jonathan Wage <jonw...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eXtreme  
View profile   Translate to Translated (View Original)
 More options 9 July, 10:45
From: eXtreme <jacek.jedrzejew...@gmail.com>
Date: Thu, 9 Jul 2009 02:45:55 -0700 (PDT)
Local: Thurs 9 July 2009 10:45
Subject: Re: LEFT JOIN / joined results not handled
How do you check your result? With toArray() method?

On 9 Lip, 11:19, James Tucker <tenlet...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 9 July, 10:50
From: James Tucker <tenlet...@gmail.com>
Date: Thu, 9 Jul 2009 02:50:48 -0700 (PDT)
Local: Thurs 9 July 2009 10:50
Subject: Re: LEFT JOIN / joined results not handled
Yes, definately. Is that not the correct way to deal with this?

On 9 Jul., 11:45, eXtreme <jacek.jedrzejew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eXtreme  
View profile   Translate to Translated (View Original)
 More options 9 July, 11:10
From: eXtreme <jacek.jedrzejew...@gmail.com>
Date: Thu, 9 Jul 2009 03:10:27 -0700 (PDT)
Local: Thurs 9 July 2009 11:10
Subject: Re: LEFT JOIN / joined results not handled
It is good, but do you pass "true" argument to that method? I mean -

>toArray(true) - it prints the array with relations.

On 9 Lip, 11:50, James Tucker <tenlet...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 9 July, 11:14
From: James Tucker <tenlet...@gmail.com>
Date: Thu, 9 Jul 2009 03:14:05 -0700 (PDT)
Local: Thurs 9 July 2009 11:14
Subject: Re: LEFT JOIN / joined results not handled
Oh my goodness. Thank you very much! Problem solved, thread closed.

On 9 Jul., 12:10, eXtreme <jacek.jedrzejew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 9 July, 13:55
From: James Tucker <tenlet...@gmail.com>
Date: Thu, 9 Jul 2009 05:55:37 -0700 (PDT)
Local: Thurs 9 July 2009 13:55
Subject: Re: LEFT JOIN / joined results not handled
Okay, swift me.. it actually works, indeed, but i have another problem
coming up:

The result is encapsuled. Which means, i do now get the joined
results, but i have to parse through them and set them to the main
array level, in order to be able to return a simple one-levelled
array / listing. I do not understand this, since i also request p.code
in my select query, but still i get no field "code" with the desired
value.

However, when i set out the SQL query directly, i get returned a
column code with the appropriate values. Thus, again, this must be
something i didnt see in Doctrine.

Does anyone know the solution to this?

On 9 Jul., 12:10, eXtreme <jacek.jedrzejew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eXtreme  
View profile   Translate to Translated (View Original)
 More options 9 July, 15:47
From: eXtreme <jacek.jedrzejew...@gmail.com>
Date: Thu, 9 Jul 2009 07:47:09 -0700 (PDT)
Local: Thurs 9 July 2009 15:47
Subject: Re: LEFT JOIN / joined results not handled
James, these are the basis of working with doctrine..

Read the manual: http://preview.tinyurl.com/nwygz7
Hydration modes are explained there.

On 9 Lip, 14:55, James Tucker <tenlet...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 10 July, 11:44
From: James Tucker <tenlet...@gmail.com>
Date: Fri, 10 Jul 2009 03:44:50 -0700 (PDT)
Local: Fri 10 July 2009 11:44
Subject: Re: LEFT JOIN / joined results not handled
Thank you. I do have trouble with this documentation, for i fail to
find what i look for. Anyway, your link basically helped me find the
correct topic, but the problem persists, for none of the optional
hydration modes will give me the results i need.

HYDRATION_NONE is the one coming closest, because it returns to me the
exact selection from my query in one single array level, but then
again it does not include the keys (field names).

I have tried all hydration modes, but i just can't find the correct
solution.

I carefully and kindly ask for help here again, after having gone
through the documentational part in detaIl.

On 9 Jul., 16:47, eXtreme <jacek.jedrzejew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eXtreme  
View profile   Translate to Translated (View Original)
 More options 10 July, 11:47
From: eXtreme <jacek.jedrzejew...@gmail.com>
Date: Fri, 10 Jul 2009 03:47:30 -0700 (PDT)
Local: Fri 10 July 2009 11:47
Subject: Re: LEFT JOIN / joined results not handled
Have you tried HYDRATE_SCALAR? It gives you a flat resultset like you
want but with column names prefixed with table aliases from query.

On 10 Lip, 12:44, James Tucker <tenlet...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 10 July, 12:00
From: James Tucker <tenlet...@gmail.com>
Date: Fri, 10 Jul 2009 04:00:42 -0700 (PDT)
Local: Fri 10 July 2009 12:00
Subject: Re: LEFT JOIN / joined results not handled
That's correct. I have tried it, but discarded it because i can't make
use of the column names with the prefixes. There must be a way to get
just a flat array with the very basic field names from the table /
select plus joins?

On 10 Jul., 12:47, eXtreme <jacek.jedrzejew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eXtreme  
View profile   Translate to Translated (View Original)
 More options 10 July, 12:16
From: eXtreme <jacek.jedrzejew...@gmail.com>
Date: Fri, 10 Jul 2009 04:16:50 -0700 (PDT)
Local: Fri 10 July 2009 12:16
Subject: Re: LEFT JOIN / joined results not handled
It is described in docs why they are there.

"However, in order to avoid ambiguities between field names all field
names in the result set are prefixed with the DQL alias that you
specified in the query."

They are there to avoid possible conflicts between field names. And
SCALAR is that "flat array with the very basic field names". :P There
is no other option. Either NONE or SCALAR, you must choose. :P

Custom hydrations are introduced in 1.2 branch.

On 10 Lip, 13:00, James Tucker <tenlet...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Tucker  
View profile   Translate to Translated (View Original)
 More options 10 July, 12:21
From: James Tucker <tenlet...@gmail.com>
Date: Fri, 10 Jul 2009 04:21:58 -0700 (PDT)
Local: Fri 10 July 2009 12:21
Subject: Re: LEFT JOIN / joined results not handled
Interesting point. Makes sense. Regarding my coding situation i find
it disturbing, because i actually deal with the option of conflict
myself, thus preventing it. But well, as you say, custom hydrations
coming up.

For the sake of completeness:

When i set my query manually in terminal / mysql client, i get my
result set,.. it does not struggle with "potential conflicts" and
other problems alike - i just get my list and the field names are
perfect. That is why i thought it must be possible to get this from
doctrine too. Now instead of making a simple doctrine query, i have to
walk through the results and delevel them each time.

I yield to thee - in any case, for your patience and your willingness
to help!

On 10 Jul., 13:16, eXtreme <jacek.jedrzejew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
eXtreme  
View profile   Translate to Translated (View Original)
 More options 10 July, 12:43
From: eXtreme <jacek.jedrzejew...@gmail.com>
Date: Fri, 10 Jul 2009 04:43:02 -0700 (PDT)
Local: Fri 10 July 2009 12:43
Subject: Re: LEFT JOIN / joined results not handled
"i actually deal with the option of conflict myself"
well, doctrine does it so that you don't have to do that :P

"When i set my query manually in terminal / mysql client, i get my
result set"
They just present resultset, they don't have to store them in an
array, which can't contain values with the same key. :P

On 10 Lip, 13:21, James Tucker <tenlet...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google