phalcon.eager-loading icon indicating copy to clipboard operation
phalcon.eager-loading copied to clipboard

toArray()

Open davidsteinsland opened this issue 9 years ago • 1 comments

Would be nice if you would create a wrapper for toArray(), making the following output:

/* Entry belongsTo Channel, Entry hasMany Files */
$result = Entries::with('Channel', 'Files');
print_r($result->toArray());
[
    0 => [
        'id' => 1,
        'channel_id' => 1,
        'Channel' => [
            'id' => 1,
            'name' => 'My Chanel'
        ],
        'Files' => [
            0 => [
                'id' => 1,
                'entry_id' => 1,
                'name' => 'foo.jpg'
            ]
        ]
    ]
]

What I do currently:

$data = [];
$i = 0;
foreach ($result as $row) {
    $data[$i] = $row->toArray();
    $data[$i]['Channel'] = $row->channel->toArray();
    foreach ($row->files as $file) {
        $data[$i]['Files'][] = $file->toArray();
    }
    $i++;
}

davidsteinsland avatar Jul 19 '15 20:07 davidsteinsland

Same issue.

erisrayanesh avatar Mar 04 '18 06:03 erisrayanesh