This one has been bothering me for a while so it's time for help.
Tables:
* posts
* tags
* posts_tags
^ i.e. hasAndBelongsToMany relationship between posts and tags.
The first thing I want to do is to find all the Posts related to one
Tag ($tag). Simple:
$posts = $this->Post->Tag->find(array('Tag.tag'=>"LIKE $tag"), 'id');
debug($posts) will look something like this:
Array
(
[Tag] => Array
(
[id] => 36
)
[Post] => Array
(
[0] => Array
(
[id] => 263
[title] => Post 1
[body] => I am very special.
)
[1] => Array
(
[id] => 264
[title] => Post 2
[body] => Me too special.
)
[..] chop, chop [..]
Now how can I, on a simple magic CakePHP way, also get all tags
related to the corresponding posts? I can probably get a foreach loop
to go thru all the posts and do a $this->Post-
>find(array('Post.id'=>"LIKE $post[id]") to get the corresponding tags
but that seems pretty excessive.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---