I have been getting some SQL errors using the Translate behavior with
save/update/delete calls. It appears that the Translate Behavior
automatically adds fields to queries for model associations even if
Model->recursive is < 0. I think this might be a bug but after
reading https://trac.cakephp.org/wiki/bugreport I am posting this to
the group first.
I have a Product Model that uses Translate behavior ('name' and
'description' fields are translated) and has BelongsTo realtionships
with ProductSize, ProductColorway, and ProductCollection.
The following code (in the controller) produces SQL errors:
$this->Product->deleteAll(array('Product.id'=>array(16,17,18)));
Here is (one) of the Queries that is produced:
Query: SELECT `Product`.*, `ProductSize`.*, `ProductColorway`.*,
`ProductCollection`.*, `I18n__name__en`.`content`,
`I18n__name__fr`.`content`, `I18n__description__en`.`content`,
`I18n__description__fr`.`content` FROM `products` AS `Product` LEFT
JOIN `i18n` AS `I18n__name__en` ON (`Product`.`id` =
`I18n__name__en`.`foreign_key` AND `I18n__name__en`.`model` =
'Product' AND `I18n__name__en`.`field` = 'name' AND
`I18n__name__en`.`locale` = 'en') LEFT JOIN `i18n` AS `I18n__name__fr`
ON (`Product`.`id` = `I18n__name__fr`.`foreign_key` AND
`I18n__name__fr`.`model` = 'Product' AND `I18n__name__fr`.`field` =
'name' AND `I18n__name__fr`.`locale` = 'fr') LEFT JOIN `i18n` AS
`I18n__description__en` ON (`Product`.`id` =
`I18n__description__en`.`foreign_key` AND
`I18n__description__en`.`model` = 'Product' AND
`I18n__description__en`.`field` = 'description' AND
`I18n__description__en`.`locale` = 'en') LEFT JOIN `i18n` AS
`I18n__description__fr` ON (`Product`.`id` =
`I18n__description__fr`.`foreign_key` AND
`I18n__description__fr`.`model` = 'Product' AND
`I18n__description__fr`.`field` = 'description' AND
`I18n__description__fr`.`locale` = 'fr') WHERE `Product`.`id` = 16
LIMIT 1
There are several built in methods in the core Model class that set
Model->recursive to -1, (Model->exists() for example). The Translate
behavior adds `AssociatedModel.*` to the list of fields in the query
but the Join statements for these tables are not present.
This is pretty easy to fix in the Translate behavior, just add...
if($model->recursive >= 0) {
}
...around the code sets the $autoFields variable. However, I am not
sure what the correct behavior should be. By definition, if Model-
>recursive is < 0 should the Translate behavior 'detach' itself since
i18n is an associated table? Or should the Translate behavior ignore
the Model->recursive setting and force the join to the i18n table?
Anyone else having the same results?
My cake version (from version.txt) is 1.2.0.7125 RC1.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---