Hello all,
When developing my application in CakePHP I need a more complex
association than, as far as I know, available in Cake.
I have the following situation:
- an Item table with some general item information (date, title etc)
and containing also an element 'type' (integer) and an element
'type_id'
- specific Item tables: EventItem, NewsItem etc which extend the Item
table
An Item table should be linked to an EventItem <==> Item.type=0, and
to a NewsItem table <==>Item.type=1,
using the type_id linker (linking to the ID in the specific table).
I tried several possibilities in Cake to have this kind of
associations, but did not find any good solution. A working solution I
have now is to dynamically bind an Item table to an EventItem table if
I know the type. However, the problem with this is that I have to bind
it everytime manually, and that I cannot mix different types. In other
words, I cannot have this data fetched:
$this->Item->findAll();
Ideally, I want this to return
Array
(
[0] => Array
(
[Item] => Array
(
[id] => 529
[type] => 0 // ==> I have an EVENT type so I
would like to fetch the data from the EventItem table
[type_id] => 25 // the ID in the EventItem table
)
[EventItem] => Array
(
[id] => 25
[start] => 'the start date'
)
)
[1] => Array
(
[Item] => Array
(
[id] => 535
[type] => 1 // I have an NEWS type so I would
like to fetch the data from the NewsItem table
[type_id] => 12 // the ID in the NewsItem
table
)
[NewsItem] => Array
(
[id] => 12
[title] => 'a title'
)
)
)
mixing the NewsItem and EventItem tables based on the Item.type field.
Anyone an idea of how I can mix these tables based on the field type
in the "base model" Item ?
Cheers,
Peter
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---