Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
ORM query, why does the array get index by pk instead of an array
bperin
July 2014
If I have a model that has a many relation and I query the related fields in ORM, why does the relation get index by the pk
for example
$posts = \Model_Post::query()
->related('user')
->related('replies')
->where('id','!=',null)
->get();
I woudl want the json structure of this to be
[{post_id:1,replies:[{post_id:2},{post_id:3}],user:{id:1}}]
but the replies is an object where the only property is another object
[{post_id:1,replies:{2:{post_id:2}},{3:{post_id:3}},user:{id:1}}]
Harro
July 2014
A get() always returns an array of objects, and any "many" relation is also always an array of objects. Doesn't matter if there is only one returned or not.
The goal here is that the result is consistent, no matter what the result is.
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
July 2014