Three tables: post, postimage, image. Postimage is a ‘join’ table between post and image as they are many to many.
post columns: post_id, post_topic_id, post_text
postimage columns: pi_post_id, pi_image_id
image columns: image_id, image_file
Post model has relation: ‘images’ => array(self::HAS_MANY, ‘PostImage’, ‘pi_post_id’),
so in the Topic controller I can get the current topic’s post_ids (from post table) and the image_ids (from postimage table) with…
$dataProvider=new CActiveDataProvider('Post', array( // all the posts for this topic
'criteria'=>array(
'condition'=>'post_topic_id='.intval($_GET['id']),
'with'=>'images',
));
but then how do I get the image_file fields for each post as well from the third table?
I’m going to attempt this using ajax in the view to pull the image_files where a post has them but wondered if there was a clean way of doing this in the controller?