Jump to content

Doctrine 1.2.2 Query Problem


djmccormick

Recommended Posts

Hello Everyone,

 

I have a question about Doctrine (I'm using 1.2.2) and the way to query for data. Here is my code:

Bootstrap: http://pastie.org/941280

Model: http://pastie.org/941275

Controller: http://pastie.org/941278

Controller debugging output: http://pastie.org/941290

 

Notice the controller and controller debugging output. I'm selecting only the username in the controller. The query it is generating according to echo $query->getSqlQuery() looks like this:

SELECT u.id AS u__id, u.username AS u__username FROM user u

 

Yet the array returned by $users->toArray() has every field populated:

Array
(
    [0] => Array
        (
            [id] => 1
            [username] => bbarker
            [password] => $1$LF7Rkevp$mROyY2ijf6g94R1VyuL0Q0
            [first_name] => Bob
            [last_name] => Barker
            [email_address] => foo@bar.com
            [created_at] => 
            [updated_at] => 
        )

)

 

I don't understand why it is returning all data and not simply the field I requested. In the Doctrine 1.2 documentation they show a similar example (it's the first example under this heading) and it's not getting every field. There is a slot for every field but those that weren't requested are blank.

 

Thank you in advance for any advice and tips from everyone.

 

Regards,

Dustin

Link to comment
Share on other sites

Doctrine remembers row objects it has previously downloaded and if it notices that you are trying to select them again, it simply returns the existing ones. Perhaps this is what happens here.

 

BTW. If you do not use row objects, hydrate the collection immediately to the array instead of calling toArray() later:

 

$users = $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.