I am facing weird issue in Yii2 I have a query which has one join with agent table and a (one to many) relation of jobs with task it works fine but issue is it returns everything in string. Below is the query:
$query = self::find()
->select("job.*, agent.first_name,agent.last_name")
->leftJoin('agent', 'job.agent_id = agent.id')
->with('tasks')
->asArray()
->all();
and the JSON encoded result:
{
"success": true,
"data": [
{
"id": "10",
"customer_id": "1",
"job_type": "normal",
"created": "2016-06-22 10:19:25",
"first_name": "Shayan",
"last_name": "",
"tasks": [
{
"id": "10",
"job_id": "10",
"title": "bring food",
"instruction": null,
"created": "2016-06-22 10:19:25",
},
{
"id": "10",
"job_id": "10",
"title": "bring pizza",
"instruction": null,
"created": "2016-06-22 10:19:25",
},
]
}
if you notice the fields like id, customer_id and job_id these all are integer but it return as string. But if I remove ->asArray() from above query it return valid type casting but issue is it skips relational and leftJoin agent table fields, it only returns job table fields here is the response after removing ->asArray() from above query.
{
"success": true,
"data": [
{
"id": 10,
"customer_id": 1,
"name": null,
"job_type": "normal",
"created": "2016-06-22 10:19:25",
},
If you notice in above response it does not have agent tables first_name, last_name and relational data tasks completely skipped but id and customer_id is in integer.
Does anyone faced same issue? your help would be highly appreciated. Thanks in advance.