Having Trouble Printing Record Weight from a Join Table

I’m building a photo gallery. I have a many to many relationship between the art and the galleries tables. Each gallery can have the art in them sorted (weighted) in their own way. I may be committing some kind of sin but it seems logical to store the weight of each art record in the join table. So now I have this in my model (does the art sorting within the gallery):


'artWeight'=>array(self::HAS_MANY, 'galXart', 'galID'),

            'art'=>array(self::MANY_MANY, 'art', 'galXart(galID, artID)',

                                'with'=>'artWeight',

                                'order'=>'artWeight.weight ASC'),

This works fine for sorting the art in each gallery. However I’m having a hard time getting the actual value of the join table’s weight field printed in my page.

I gather the art from the galleries relationship this way:


$art         = $model->art;

$this->renderPartial('_thumbs',array(

    'gallery'    => $model,

    'art'        => $art,

)); 

This may seem foolish to you pros, but I can’t figure out how to access the weight field buried in the $art object.

Suggestions? Thanks!

The $art variable is not an object but an array.

So you need to do a foreach-loop on the variable to get the ‘artWeight’-relation which again is an array which you should do a foreach-loop on.

Something like this:




foreach ($art as $a)

{

  foreach ($a->artWeight as $weight)

  {

    echo $weight->weight;

  }

}



Ah recursive stuff. I was kind of hoping I could avoid it. However it does work! Thank you Komodo!