if you have two different types of photos for your news, which should use the same photo-model you can define other model-aliases..... like this:
app/models/article.php: var $hasAndBelongsToMany = array( 'Photo' => array( 'className' => 'Photo', // should be the name of the Photo- Model // rest of habtm defintion of the normal photos ) ); var $belongsTo = array( 'MainPhoto' => array( 'className' => 'Photo', // should be the name of the Photo- model ) ); app/models/photo.php var $hasAndBelongsToMany = array( 'Article'=> array( 'className' => 'Article' ) ); var $hasMany = array( 'Article' => array( 'className' => 'Article' ) ); providing a main_photo_id field in your articles-table you can now do normal find()'s and cake will fetch all the 'Photos' which are related via habtm and the one 'MainPhoto' as they were two different models... no need for an extra field in the join-table. you could also define the relation like Article hasOne MainPhoto and Photo belongsTo Article (and then you have to provide an article_id field in your photos-table), but then you cant use the same MainPhoto for different articles.... its up to you how to do it, but basically, if you want to use the same model for different relations, you can use different alias-names for this model On Mar 11, 11:52 am, Xoubaman <xouba...@gmail.com> wrote: > Just model it like a normal HABTM relationship, no special syntaxis, > and add the field in the database. > > When saving, try this: > > http://teknoid.wordpress.com/2008/09/24/saving-extra-fields-in-the-jo... > > I haven't done it before, so i can't secure his fiability, but looks > good. > > On Mar 11, 10:38 am, mattalexx <mattal...@gmail.com> wrote: > > > > > What's the syntax for adding an "extra field" to the > > $hasAndBelongsToMany var? > > > Thank you for you response. > > > On Mar 11, 2:43 am, Xoubaman <xouba...@gmail.com> wrote: > > > > You can model it like a normal HABTM relationship with an extra field > > > named main_photo. > > > > On Mar 11, 8:30 am, mattalexx <mattal...@gmail.com> wrote: > > > > > My articles have and belong to many photos. This is so when the photo > > > > is seen somewhere else on the site, I can have a "see related > > > > articles". Each article also has one main photo. I can't seem to > > > > figure out the syntax for this in APP/models/article.php file and in > > > > APP/models/photo.php. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---