CodeIgniter: adding a $subresult to an object $result by an ActiveRecord result ID
I think you just need:
$record->threads = $threads;
EDIT:
You just need to assign the reference in your foreach (note the &
next to $record
):
foreach($records as &$record){ //... $record->threads = $threads;}return $records;
If the method shown by rojoca doesn't work, you could do this:
$records = $sql->result_array();
Then loop through as usual (except do $record_id = $record['record_id']
instead of $record->record_id
), and reference your row like this:
$records[$record_id]['threads'] = $threads;
Though you may not want to rely so heavily on that record_id column always matching perfectly with your iteration index.