Hi!

I use translation behavior in CakePHP 1.2. The question is about how
to set model alias in hasMany relation? Why I need it?

I my case I have two models: Personal and Country. Personal uses
Country by two associations - country_id and citizenship_id. Here is
belongsTo part of personal.php:

        var $belongsTo = array(
                        'Country' => array('className' => 'Country',
                                                                'foreignKey' => 
'country_id',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => ''
                        ),
                        'Citizenship' => array('className' => 'Country',
                                                                'foreignKey' => 
'citizenship_id ',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => '',
                        ),
        );

country.php code is:

<?php
class Country extends AppModel {

        var $name = 'Country';
        var $useTable = 'countries';
        var $actsAs   = array('Translate' => array('name'));
        var $displayField = 'name';
        var $order = 'I18n__name.content';
}
?>

As result I've got following SQL:

SELECT `Country`.`id`, `I18n__name`.`content` FROM `countries` AS
`Country` LEFT JOIN `i18n` AS `I18n__name` ON (`Country`.`id` =
`I18n__name`.`foreign_key` AND `I18n__name`.`model` = 'Country' AND
`I18n__name`.`field` = 'name') WHERE `I18n__name`.`locale` = 'rus'
ORDER BY `I18n__name`.`content` ASC

SELECT `Citizenship`.`id`, `I18n__name`.`content` FROM `countries` AS
`Citizenship` LEFT JOIN `i18n` AS `I18n__name` ON (`Citizenship`.`id`
= `I18n__name`.`foreign_key` AND `I18n__name`.`model` = 'Citizenship'
AND `I18n__name`.`field` = 'name') WHERE `I18n__name`.`locale` = 'rus'
ORDER BY `I18n__name`.`content` ASC

The translation behavior looks for translation for Citizenship model
in i18n table. If I replace in translation.php

.'.model' => $model->alias

to

.'.model' => $model->name

then it works ok.

It is possible to set model alias in the belongsTo association?

Thanks!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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