Hello,
I have some data that must be stored in a tree structure. Here is the
SQL used to create that data's table:
drop table if exists fields;
create table fields (
id int(11) unsigned not null auto_increment,
created_at datetime not null,
updated_at datetime not null,
template_id int(11) unsigned not null,
field_id int(11) unsigned,
type varchar(255) not null,
name varchar(255) not null,
label varchar(255) not null,
required tinyint(1) default 0,
weight tinyint(1) default 0,
primary key (id)
);
I baked a model and a scaffold controller for this data using `cake
bake` but the SQL generated from this model is faulty. Specifically,
the following is invalid as the same name "Field" is aliased twice:
SELECT COUNT(*) AS `count` FROM `fields` AS `Field` LEFT JOIN
`templates` AS `Template` ON (`Field`.`template_id` = `Template`.`id`)
LEFT JOIN `fields` AS `Field` ON (`Field`.`field_id` = `Field`.`id`)
WHERE 1 = 1;
Here are the model relationships that are generating this SQL:
<?php
class Field extends AppModel {
var $name = 'Field';
var $displayField = 'name';
// Validations omitted
var $belongsTo = array(
'Template' => array(
'className' => 'Template',
'foreignKey' => 'template_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Field' => array(
'className' => 'Field',
'foreignKey' => 'field_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'Field' => array(
'className' => 'Field',
'foreignKey' => 'field_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
Does anyone know what I can do so that there is no duplicate alias on
the self-join?
Thanks,
Thomas
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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