views:

112

answers:

1

Hi,

so..I followed doctrine documnetation to get started. Here is the documentation http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:retrieving-related-records

My code is

$User = Doctrine_Core::getTable("User")->find(1);

when I access relations by $User->Phonenumbers, it works. When I convert User object to array by using toArray() method, it does not convert relations to array. It simply display $User data.

Am i missing something?

+1  A: 

By using the find method you've only retrieved the User data which is why the return of toArray is limited to that data. You need to specify the additional data to load, and the best place to do this is usually in the original query. From the example you linked to, add the select portion:

$q = Doctrine_Query::create()
    ->select('u.*, e.*, p.*')  // Example only, select what you need, not *
    ->from('User u')
    ->leftJoin('u.Email e')
    ->leftJoin('u.Phonenumbers p')
    ->where('u.id = ?', 1);

Then when toArray'ing the results from that, you should see the associated email and phonenumber data as well.

Kevin