Iterating through results

I’m having trouble iterating through results in an active record object. Can someone provide a code example please.

$data = MyTable::model()->with('MyOtherTable')->find(...);

$eg = $data->myColumnFromMyTable;


$eg = $data->myColumnFromMyTable;  // value still the same as before

Further more I need to do this across a table join, but haven’t worked out how to do it on a single table yet.

find only returns a single result.

I needed findAll which returns an array of active records which can be iterated using foreach.

simply do:

$data = MyTable::model()->with('MyOtherTable')->findAll(...);

foreach ($data as $item)




I didn’t get if your post is a self-aswer or not… hope it helps!

Hi zaccaria

Yes, I worked it out. I always answer my own posts if I work it out. Hopefully it will help someone else (maybe even me in a few a months time!). But thanks anyway.