У меня есть следующая ассоциация
class User
{
....
/**
* @OneToMany(targetEntity="UserNote", mappedBy="user", fetch="EAGER")
*/
public $userNote;
....
}
class UserNote implements
{
....
/**
* @ManyToOne(targetEntity="User", inversedBy="userNote")
* @JoinColumn(name="id_user", referencedColumnName="id_user")
*/
public $user;
....
}
Приведенная выше ассоциация выдает следующий объект как результат, когда я выбираю одного пользователя, у которого есть какое-то UserNote:
App\Models\Entity\User Object
(
[id] => 4
[name] => Filipe Rodrigues
[email] => filipe@email.com.br
[login] => master
[password] => *********
[date] => DateTime Object
(
[date] => 2016-05-04 00:00:00.000000
[timezone_type] => 3
[timezone] => UTC
)
[lastLogin] => DateTime Object
(
[date] => 2017-08-09 11:45:38.000000
[timezone_type] => 3
[timezone] => UTC
)
[numLogin] => 161
[fone1] => 1112345678
[fone2] =>
[cep] => 09112000
[adress] => Rua Sila NAlon Gonzzaga
[cpf] => 289.233.498-52
[typeUser] => 3
[facebook] =>
[site] =>
[plan] =>
[idPlan] => 1
[note] =>
[fl_vip] =>
[fl_trial] => 0
[fl_cob] => 0
[recorrenceCode] => 0566AEA4DADA9861147E5F95DD2AF24B
[billingDay] => 13
[status] => 8
[token] =>
[parent] =>
[userNote] => Doctrine\ORM\PersistentCollection Object
(
[snapshot:Doctrine\ORM\PersistentCollection:private] => Array
(
[0] => App\Models\Entity\UserNote Object
(
[id] => 1
[note] => teste
[date] => DateTime Object
(
[date] => 2018-01-02 00:00:00.000000
[timezone_type] => 3
[timezone] => UTC
)
[user] => App\Models\Entity\User Object
*RECURSION*
)
)
......
Итак, когда я использую json_encode, я получаю следующий результат:
{
"id": 4,
"name": "Filipe Rodrigues",
"email": "filipe@vitrinekar.com.br",
"login": "master",
"password": "ndtidis@23",
"date": {
"date": "2016-05-04 00:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"lastLogin": {
"date": "2017-08-09 11:45:38.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"numLogin": 161,
"fone1": "1112345678",
"fone2": null,
"cep": "09112000",
"adress": "Rua Sila NAlon Gonzzaga",
"cpf": "289.233.498-52",
"typeUser": 3,
"facebook": null,
"site": null,
"plan": null,
"idPlan": 1,
"note": null,
"fl_vip": null,
"fl_trial": 0,
"fl_cob": 0,
"recorrenceCode": "0566AEA4DADA9861147E5F95DD2AF24B",
"billingDay": 13,
"status": 8,
"token": null,
"parent": null,
"userNote": {}
}
UserNote не преобразовал, как я могу преобразовать ассоциацию доктрины, используя json_encode?
Кто-нибудь может мне помочь?