I have a table laid out for a typical nested comments system (like in
most blogs, etc):
comments (id int auto increment, parent_id int, body text, primary key
(id), foreign key (parent_id) references comments (id))
In the model I have $hasMany = array('Comments') and $belongsTo =
array('Comments'). I'm doing this because it wouldn't make sense to
use a join table so $hasAndBelongsToMany is out of the question. When
it comes time to do a findAllThreaded() on my model I end up with an
error like:
"Warning (512): SQL Error: 1066: Not unique table/alias:
'Comment' [CORE/cake/libs/model/datasources/dbo_source.php, line 440]"
This makes sense, because the query itself does two aliases but
they're both to the same thing:
"SELECT `Comment`.`id`, `Comment`.`user_id`, `Comment`.`parent_id`,
`Comment`.`link_id`, `Comment`.`subject`, `Comment`.`hostname`,
`Comment`.`created`, `Comment`.`modified`, `Comment`.`score`,
`Comment`.`body`, `Comment`.`sfw`, `Link`.`id`, `Link`.`linkname` FROM
`comments` AS `Comment` LEFT JOIN `comments` AS `Comment` ON
(`Comment`.`parent_id` = `Comment`.`id`) LEFT JOIN `links` AS `Link`
ON (`Comment`.`link_id` = `Link`.`id`) WHERE `id` = 1"
After asking in irc and googling a bit on how to handle this, the best
reference I found to the problem was in this bug report:
https://trac.cakephp.org/ticket/1618. Unfortunately, aside from
linking a changeset it didn't explain the issue much more. Is a
recursive relationship like this possible with just one model in Cake,
or do I need to add the overhead of a join table?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---