On Feb 11, 5:04 am, nebbian <[email protected]> wrote:
> 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(

^^ CompetitionAnswer""

>                                                                 'className' 
> => 'CompetitionAnswer',
>                                                                 'foreignKey' 
> => 'CompetitionID',
>                                                                 'conditions' 
> => '',
>                                                                 'fields' => 
> '',
>                                                                 'order' => 
> array('CompetitionAnswers.CompetitionID DESC',
>                                                                               
>           'CompetitionAnswers.CompetitionAnswerOrder ASC'),

^^ CompetitionAnswer"" x2

>                                                                 '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(

^^ Is that a typo
>                                                                 '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]

>From the errors in your model file that's to be expected.
>
> "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.

Try again after correcting your model definitions. I hope that's a
legacy database - otherwise why have you created such a repetitive and
unconventional schema (e.g.
"CompetitionAnswer.CompetitionAnswerText")? You can and should delete
anything that is the default/following convention too.

hth,

AD
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to