You could also add a model and id field, and set the belongsTo conditions in
Photo specifying foreignKey and conditions.
So you add two fields to table photos:
model
record_id
And then on Photo model:
<?php
class Photo extends AppModel
{
var $name = 'Photo';
var $belongsTo = array(
'Person' => array(
'foreignKey' => 'record_id',
'conditions' => 'Photo.model = \'Person\''
),
'Group' => array(
'foreignKey' => 'record_id',
'conditions' => 'Photo.model = \'Group\''
)
);
}
?>
http://manual.cakephp.org/chapter/models
-MI
---------------------------------------------------------------------------
Remember, smart coders answer ten questions for every question they ask.
So be smart, be cool, and share your knowledge.
BAKE ON!
blog: http://www.MarianoIglesias.com.ar
-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Zach Cox
Enviado el: Viernes, 04 de Mayo de 2007 03:32 p.m.
Para: [email protected]
Asunto: Re: Polymorphic Associations
Imagine a social networking site with people, groups, & photos:
- Person hasMany Photo
- Group hasMany Photo
- Photo belongsTo Person, Group
Then you'd need to do:
photos
- id
- person_id
- group_id
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---