Thanks for the quick response Brian! When I add:
<?php echo $product['Color']['name']; ?> I get error: Notice (8): Undefined index: Color [APP\views\products\index.ctp, line 48] Any suggestions? Thanks! On Apr 3, 6:56 pm, brian <bally.z...@gmail.com> wrote: > The SQL query is fetching Color.name. You're looking in the Product > array. The Color name will be in the Color array. > > <?php echo $product['Color']['name']; ?> > > When in doubt, do a debug($this->data) in your view. > > On Fri, Apr 3, 2009 at 9:48 PM, justclint <justcl...@gmail.com> wrote: > > > My app is working but a couple of my fields are not pulling the data I > > want. > > > I have a table called products and another table called colors. My > > colors table has 2 fields, id and name. > > > When adding the product, you select the color (from drop down menu) > > and it will insert the color id into the color_id field of the > > products table. > > > Once I add a product, instead of displaying the actual color it shows > > the colors id. (ie: 2 instead of blue) > > > How do I get my page to pull the actual color name not the color id? > > > When launching the page it does the following query: > > > SELECT `Product`.`id`, `Product`.`name`, `Product`.`category_id`, > > `Product`.`material_id`, `Product`.`color_id`, `Product`.`sport_id`, > > `Product`.`price`, `Product`.`image_link`, `Product`.`buy_link`, > > `Category`.`id`, `Category`.`name`, `Material`.`id`, > > `Material`.`name`, `Color`.`id`, `Color`.`name`, `Sport`.`id`, > > `Sport`.`name` FROM `products` AS `Product` LEFT JOIN `categories` AS > > `Category` ON (`Product`.`category_id` = `Category`.`id`) LEFT JOIN > > `materials` AS `Material` ON (`Product`.`material_id` = > > `Material`.`id`) LEFT JOIN `colors` AS `Color` ON > > (`Product`.`color_id` = `Color`.`id`) LEFT JOIN `sports` AS `Sport` ON > > (`Product`.`sport_id` = `Sport`.`id`) WHERE 1 = 1 LIMIT 20 > > > I think I need the following part of the query to be changed from: > > > `colors` AS `Color` ON (`Product`.`color_id` = `Color`.`id`) > > > to > > > `colors` AS `Color` ON (`Product`.`color_id` = `Color`.`name`) > > > My controller is just the default one after creating through the > > console so Products->index looks like: > > > function index() { > > $this->Product->recursive = 0; > > $this->set('products', $this->paginate()); > > } > > > My Product model looks like: > > > var $belongsTo = array( > > 'Color' => array( > > 'className' => 'Color', > > 'foreignKey' => 'color_id', > > 'conditions' => '', > > 'fields' => '', > > 'order' => '' > > ) > > ); > > > My Color model looks like this: > > > var $hasMany = array( > > 'Product' => array( > > 'className' => 'Product', > > 'foreignKey' => 'color_id', > > 'dependent' => false, > > 'conditions' => '', > > 'fields' => '', > > 'order' => '', > > 'limit' => '', > > 'offset' => '', > > 'exclusive' => '', > > 'finderQuery' => '', > > 'counterQuery' => '' > > ) > > ); > > > And Products->index view looks like this: > > > <tr<?php echo $class;?>> > > <td> > > <?php echo $product['Product']['id']; ?> > > </td> > > <td> > > <?php echo $product['Product']['name']; ?> > > </td> > > > <td> > > <?php echo $product['Product']['color_id']; ?> > > </td> > > > Your help is greatly appreciated. > > > 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---