I don't think problem is with models, because if I comment the
variable "$hasMany=UnitI18n" in Unit model (i.e. Unit and UnitI18n are
NOT related) and Cake doesn't run queries on unit_18ns table but only
on unts.

Adding the variable "$hasMany" in Unit model causes Cake to run query
on unit_i18ns table but data is not presented in resulted array.

I tried with prepared sql_query  in mysql client and query is OK -
MySQL server returns correct data.

On Apr 21, 3:54 pm, senser <[EMAIL PROTECTED]> wrote:
> ### filemodels/category_i18ns.php ###
>
> class CategoryI18n extends AppModel{
>
>         var $name='CategoryI18n';
>         var $recursive=2;
>         var
> $validate=array('category_id'=>array('required'=>VALID_NOT_EMPTY,
>                                                                               
>   'number'=>VALID_NUMBER,
>                                                                               
>   'length'=>array('rule'=>array('between', 1, 2))),
>                                         
> 'locale'=>array('required'=>VALID_NOT_EMPTY,
>                                                                 
> 'permitted'=>array('rule'=>array('validLocale'))),
>                                         
> 'content'=>array('required'=>VALID_NOT_EMPTY,
>                                                                 
> 'length'=>array('rule'=>array('between', 1, 50)))
>                                         );
>
> }
>
> #################################
>
> ### filemodels/unit_i18ns.php ###
>
> class Unit extends AppModel{
>
>         var $name='Unit';
>         var $recursive=2;
>         var $actsAs=array('Language');
>
>         var $hasMany=array('UnitI18n'=>array('className'=>'UnitI18n',
>                                                                               
>   'conditions'=>'',
>                                                                               
>   'order'=>'UnitI18n.locale DESC',
>                                                                               
>   'dependent'=>true,
>                                                                               
>   'foreignKey'=>'unit_id',
>                                                                               
>   'finderQuery'=>'',
>                                                                               
>   'fields'=>array(),
>                                                                               
>   'exclusive'=>false));}
>
> #################################
>
> On Apr 21, 8:14 am, "Federico Rinaldi" <[EMAIL PROTECTED]>
> wrote:
>
> > Can you provide also the CategoryI18n and the UnitI18nmodels?
>
> > 2008/4/21 senser <[EMAIL PROTECTED]>:
>
> > > any  ideas ???
>
> > > On Apr 19, 10:33 am, senser <[EMAIL PROTECTED]> wrote:
> > > > Hello!
>
> > > > I have fivemodels: Offers, Category, CategoryI18n, Unit & UnitI18n
> > > > and they're associated as follows:
>
> > > > Offer--belongsTo-->Category
> > > > Offer--belongsTo-->Unit
> > > > Category--hasMany-->CategoryI18n
> > > > Unit--hasMany-->UnitI18n
>
> > > > and here is the code frommodels:
>
> > > > ### filemodels/offer.php ###
> > > > class Offer extends AppModel{
>
> > > >         var $name='Offer';
> > > >         var $recursive=2;
>
> > > >         var $belongsTo=array('Unit'=>array('className'=>'Unit',
>
> > > 'conditions'=>'',
>
> > > 'order'=>'',
>
> > > 'dependent'=>true,
>
> > > 'foreignKey'=>'unit_id',
>
> > > 'finderQuery'=>'',
>
> > > 'fields'=>array(),
>
> > > 'exclusive'=>false),
>
> > > 'Category'=>array('className'=>'Category',
>
> > > 'conditions'=>'',
>
> > > 'order'=>'',
>
> > > 'dependent'=>true,
>
> > > 'foreignKey'=>'category_id',
>
> > > 'finderQuery'=>'',
>
> > > 'fields'=>array(),
>
> > > 'exclusive'=>false));
>
> > > > }
>
> > > > ########################
>
> > > > ### filemodels/category.php ###
> > > > class Category extends AppModel{
>
> > > >         var $name='Category';
> > > >         var $recursive=2;
>
> > > >         var
> > > $hasMany=array('CategoryI18n'=>array('className'=>'CategoryI18n',
>
> > >         'conditions'=>'',
>
> > >         'order'=>'CategoryI18n.locale DESC',
>
> > >         'dependent'=>true,
>
> > >         'foreignKey'=>'category_id',
>
> > >         'finderQuery'=>'',
>
> > >         'fields'=>array(),
>
> > >         'exclusive'=>false));}
>
> > > > ########################
>
> > > > ### filemodels/unit.php ###
> > > > class Unit extends AppModel{
>
> > > >         var $name='Unit';
> > > >         var $recursive=2;
>
> > > >         var $hasMany=array('UnitI18n'=>array('className'=>'UnitI18n',
>
> > >         'conditions'=>'',
>
> > >         'order'=>'UnitI18n.locale DESC',
>
> > >         'dependent'=>true,
>
> > >         'foreignKey'=>'unit_id',
>
> > >         'finderQuery'=>'',
>
> > >         'fields'=>array(),
>
> > >         'exclusive'=>false));}
>
> > > > ########################
>
> > > > So when I try to fetch some offers recursively, I get the CategoryI18n
> > > > results, but not UnitI18n.
> > > > As you can see from the code, bothmodels(Category & Unit) arerelatedto
> > > Offer in same manner, and UnitI18n & CategoryI18n
> > > > respectively arerelatedto Unit & Category.
>
> > > > $this->Offer->findAll(array(), array(), 'Offer.last_edit_date DESC',
> > > > 1, 1, 2); returns this:
>
> > > > Array
> > > > (
> > > >     [0] => Array
> > > >         (
> > > >             [Offer] => Array
> > > >                 (
> > > >                     [id] => 4
> > > >                     [category_id] => 2
> > > >                     [type_id] => 1
> > > >                     [status_id] => 2
> > > >                     [country_id] => 4
> > > >                     [region_id] =>
> > > >                     [settlement_id] =>
> > > >                     [district_id] =>
> > > >                     [qunatity] => 0
> > > >                     [unit_id] => 1
> > > >                     [currency_id] => 1
> > > >                     [price_per_unit] =>
> > > >                     [price_1] => 123
> > > >                     [price_2] => 234
> > > >                     [date] => 2008-04-18 13:51:48
> > > >                     [last_edit_date] => 2008-04-18 13:51:48
> > > >                 )
>
> > > >             [Unit] => Array
> > > >                 (
> > > >                     [id] => 1
> > > >                 )
> > > > [Category] => Array
> > > >                 (
> > > >                     [id] => 2
> > > >                     [category_id] => 1
> > > >                     [CategoryI18n] => Array
> > > >                         (
> > > >                             [0] => Array
> > > >                                 (
> > > >                                     [id] => 4
> > > >                                     [category_id] => 2
> > > >                                     [locale] => bul
> > > >                                     [content] => 1-стайни
> > > >                                 )
>
> > > >                             [1] => Array
> > > >                                 (
> > > >                                     [id] => 3
> > > >                                     [category_id] => 2
> > > >                                     [locale] => eng
> > > >                                     [content] => 1-room
> > > >                                 )
>
> > > >                         )
>
> > > >                 )
> > > > )
>
> > > > So Categories are fetched recursively but Units NOT.
> > > > And finally my biggest confusion is the fact that actually Cake runs
> > > > SQL queries for fetching UnitI18n as CategoryI18n but the result is
> > > > missing in the array
>
> > > > Here is what controller produces as SQL statements:
>
> > > > SELECT `Unit`.`id` FROM `units` AS `Unit` WHERE `Unit`.`id` = 1
> > > > SELECT `UnitI18n`.`id`, `UnitI18n`.`unit_id`, `UnitI18n`.`locale`,
> > > > `UnitI18n`.`content` FROM `unit_i18ns` AS `UnitI18n` WHERE
> > > > `UnitI18n`.`unit_id` IN (1) ORDER BY `UnitI18n`.`locale` DESC
> > > > SELECT `Category`.`id`, `Category`.`category_id` FROM `categories` AS
> > > > `Category` WHERE `Category`.`id` = 2
> > > > SELECT `CategoryI18n`.`id`, `CategoryI18n`.`category_id`,
> > > > `CategoryI18n`.`locale`, `CategoryI18n`.`content` FROM
> > > > `category_i18ns` AS `CategoryI18n` WHERE `CategoryI18n`.`category_id`
> > > > IN (2) ORDER BY `CategoryI18n`.`locale` DESC
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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