Hi,
I have the following models:
class Competition extends AppModel {
var $name = 'Competition';
var $useTable = 'Competition';
var $primaryKey = 'CompetitionID';
var $recursive = 2;
var $hasMany = array(
'CompetitionAnswers' => array(
'className' =>
'CompetitionAnswer',
'foreignKey' =>
'CompetitionID',
'conditions' =>
'',
'fields' => '',
'order' =>
array('CompetitionAnswers.CompetitionID DESC',
'CompetitionAnswers.CompetitionAnswerOrder ASC'),
'dependent' =>
true
)
);
class CompetitionAnswer extends AppModel {
var $name = 'CompetitionAnswer';
var $useTable = 'CompetitionAnswer';
var $primaryKey = 'CompetitionAnswerID';
var $recursive = 2;
var $displayField = 'CompetitionAnswerText';
var $order = array(
'CompetitionAnswer.CompetitionID DESC',
'CompetitionAnswer.CompetitionAnswerOrder ASC'
);
var $belongsTo = array(
'CompetitionID' => array(
'className' =>
'Competition',
'foreignKey' =>
'CompetitionID',
'conditions' =>
'',
'fields' => '',
'order' => ''
)
);
Everything works fine, until I try a cascade delete:
if ($this->Competition->del($id)) { ...
When I get the following error:
SQL Error: 1109: Unknown table 'CompetitionAnswer' in order clause
[CORE/cake/libs/model/datasources/dbo_source.php, line 512]
"SELECT `CompetitionAnswers`.`CompetitionAnswerID` FROM
`CompetitionAnswer` AS `CompetitionAnswers` WHERE
`CompetitionAnswers`.`CompetitionID` = 21 ORDER BY
`CompetitionAnswer`.`CompetitionID` DESC[...]"
It appears as if this is not loading the order field that I specified
in my HasMany clause, instead it is loading the default order field
for my class, but still calling the table the same way that was
specified in the HasMany clause.
I can't get rid of the table specification in the order clause,
because then I get an ambiguous table name error.
Is this a bug in Cake? It sure looks like it to me. It only happens
on a cascade delete, not any other form of database access.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---