Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM query, why does the array get index by pk instead of an array
  • 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}}]
  • 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.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion