0

I have a query:

UserQuery::create()
   ->leftJoinWith('User.Employee')
   ->select(array('Email','Password','Status','Employee.Email','Employee.FirstName','Employee.LastName'))
   ->find();

How to get Employee table as nested object, not like list of columns?

I have:

[
   "Email":"test@test.pl",
   "Password":"test",
   "Status":true,
   "Employee.Id":"4",
   "Employee.FirstName":"roman",
   "Employee.LastName":"stonoga"
]

But I have to have:

[
   "Email":"test@test.pl",
   "Password":"test",
   "Status":true,
   "Employee": { 
      "Id":"4",
      "FirstName":"roman",
      "LastName":"stonoga"
   }
]

Many thanks for any help!

Mateusz K.
  • 111
  • 6

2 Answers2

0

This is because Propel is treating your array the same way as how your objects are structured/related. i.e. Employee as sub-entity within User, and NOT as one object.

If you want one object, then maybe a view will help.

Another view-related question

Community
  • 1
  • 1
Qiniso
  • 2,587
  • 1
  • 24
  • 30
0

You should use a foreign key for this

$userArray = $User->toArray()
$userArray['employee'] = $User->getEmployee()->toArray()
kripple
  • 151
  • 6