This works perfectly! Thank you
2008/8/19 grigri <[EMAIL PROTECTED]>: > > Set up an extra relationship, like so: > > class Category extends AppModel { > // ... > var $belongsTo = array( > 'CoverProduct' => array( > 'className' => 'Product', > 'foreignKey' => 'imgpath', > 'fields' => array('imgpath') > ) > ); > // ... > } > > Yes, it does "sound" weird that a category belongs to its cover, as in > real-world usage we'd say the opposite. But this is the way cake works > things. > > Now when you do your pagination and set $categories in the view: > > foreach ($categories as $cat) { > echo $cat['Category']['nome']; // Category title > echo $html->image($cat['CoverProduct']['imgpath']); // Category > image > } > > hth > grigri > > On Aug 19, 5:08 am, "Henrique Machado" <[EMAIL PROTECTED]> wrote: >> Hello! >> This is my first messa ge here. >> Sorry my bad english, i'm from brazil >> >> Scenario: >> >> Category hasMany Products >> Products belongsTo Category >> >> category table: >> >> `id` int(10) unsigned NOT NULL auto_increment, >> `nome` varchar(255) collate utf8_unicode_ci default NULL, >> `created` datetime default NULL, >> `slug` varchar(255) collate utf8_unicode_ci default NULL, >> `imgcover` int(11) NOT NULL, >> PRIMARY KEY (`id`) >> >> products: >> >> `id` int(10) unsigned NOT NULL auto_increment, >> `imgpath varchar(255) collate utf8_unicode_ci default NULL, >> `legend` varchar(255) collate utf8_unicode_ci default NULL, >> `created` datetime default NULL, >> `slug` varchar(255) collate utf8_unicode_ci default NULL, >> `category_id` int(10) unsigned default NULL, >> PRIMARY KEY (`id`), >> KEY `fotos_obra` (`obra_id`) >> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci >> AUTO_INCREMENT=27 ; >> >> My problem: I need to show the imgcover (is the product id) in my >> category index: >> function index() { >> $this->Category->recursive = 1; >> $this->set('categories', $this->paginate()); >> } >> >> The "php" way is do an foreach categories and loop each cagotegory to >> do something like: SELECT imgpath FROM PRODUCTS WHERE id = >> category.imgcover >> >> But, in the cake way? >> >> Thanks > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---