I found solutions, but it's very hopeless...

                $product = $this->Product->find('first', array(
                        'conditions' => array(
                                'Product.id' => $id)));

                $category = $this->Category->find('first', array(
                        'conditions' => array(
                                'Category.id' => 
$product['Product']['category_id']), // or
$product['Category']['id']
                        'fields' => array(
                                'Category.name',
                                'Category.slug')));

                $product['Category']['name'] = $category['Category']['name']; //
it's manual writing:(
                $product['Category']['slug'] = $category['Category']['slug'];

                $this->set('product', $product);


Many disadvantages:
1. Fist find() return all relations (Product belongsTo Category)
without translate
2. Second find() returl all relations (Category hasMany Product)
without translate
3. I must manual setting 'id' for second find()
4. I must manual setting data from translated Category to Product
5. This example is very simple, but I have very more relations
model...

My question is: Why just first find() function not return translated
data for relations model?


On Oct 9, 12:26 pm, kicaj <ki...@kdev.pl> wrote:
> My code:
>
> class Product extends AppModel {
>         var $name = 'Product';
>         var $actsAs = array(
>                 'Translate' => array(
>                         'name'));
>         var $belongsTo = array(
>                 'Category' => array(
>                         'className' => 'Category',
>                         'foreignKey' => 'category_id'));
>
> }
>
> class Category extends AppModel {
>         var $name = 'Category';
>         var $actsAs = array(
>                 'Translate' => array(
>                         'name'));
>         var $hasMany = array(
>                 'Product' => array(
>                         'className' => 'Product',
>                         'foreignKey' => 'category_id',
>                         'dependent' => false));
>
> }
>
> I drops fields 'name' from tables products and categories and when I
> want read my product: $this->Product->findById($id), I get results
> like this:
>
> Array
> (
>     [Product] => Array
>         (
>             [id] => 10
>             [category_id] => 1
>             [locale] => pol    /* it's okey! */
>             [name] => Some text    /* it's okey!' */
>         )
>
>     [Category] => Array
>         (
>             [id] => 1
>             [created] => 2009-10-03 11:22:11
>             [modified] => 2009-10-03 11:22:11
>         )
> )
>
> My question is: Why there is no field [Category][name] (and [Category]
> [locale])?
--~--~---------~--~----~------------~-------~--~----~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to