I just found DataMapper for CI's built in to_json
and all_to_json
methods, which saved me a ton of time.
How can I return relations with the result?
Currently my code looks like this:
$homes = new Home();
$homes->include_related('address')->get();
$homes->include_related('album')->get();
$homes->get();
$homes->set_json_content_type();
echo $homes->to_json();
However I'm only getting back the home itself, rather than the nested information.
EDIT:
I've found that you can simply add those fields to the array parameter, however, if I use all_to_json($fields);
it returns the first row perfectly, but the second nested comes back as NULL. Still think it's my fault, but I didn't know if anyone's seen this before.
Here is my current output.
{
"id": 1,
"latitude": "0",
"longitude": "0",
"price": "173000",
"sqft": "2100",
"room_count": "3",
"bath_count": "2",
"created": "1333209034",
"updated": "1333209034",
"status": "active",
"address": [
1
],
"album": []
}
In my data, if I view the raw output, I see the full address. In my JSON I see a number 1. How can I display this data rather than the number?