I have an activity table with 3 $belongsTo reference keys. I need the join information from these id's i.e. to show the commenttext - I don't want to store the text twice... (same for post and topic).
Activity table: id | post_id | comment_id | topic_id
In each row only post_id OR comment_id OR topic_id is set, the other two id fields are NULL.
So i.e. if post_id = 55, comment_id = NULL, topic_id = NULL I get this:
Array
(
[0] => Array
(
[Activity] => Array
(
[id] => 1
[post_id] => 55
[comment_id] =>
[topic_id] =>
)
[Post] => Array
(
[id] => 55
[name] => Post #1
[description] => This is Post #1.
...
)
[Comment] => Array
(
[id] =>
[post_id] =>
[titel] =>
[description] =>
...
[created] =>
[modified] =>
)
[Topic] => Array
(
[id] =>
...
[created] =>
[modified] =>
)
)
[1] => Array
(
...
Is there a way to join only if the reference id is NOT NULL? I don't want to kill the empty arrays after the find with a php for-each loop.
Another idea was this database table: id | activitytype_id | refid to join with dynamic binding the necessary table depending on the activitytype_id. - That didn't work as well...
That's what I want - is that possible?
Array
(
[0] => Array
(
[Activity] => Array
(
[id] => 1
[post_id] => 55
[comment_id] =>
[topic_id] =>
)
[Post] => Array
(
[id] => 55
[name] => Post #1
[description] => This is Post #1.
...
)
)
[1] => Array
(
[Activity] => Array
(
[id] => 2
[post_id] =>
[comment_id] => 2
[topic_id] =>
)
[Comment] => Array
(
[id] => 2
[post_id] => 4
[titel] => Blabla
[description] => This is the comment description
...
[created] => 2011-01-01 01:30:00
[modified] => 2011-01-01 01:30:00
)
)
[2] => Array
(
...
Thanks in advance! :-)