Re: retrieving data from another table

2009-05-18 Thread justclint

Ok, im not sure what I was doing wrong but it was just as simple as
you mentioned. I just added $this->Product->recursive = 2; and viola,
everything was fetched properly.

Thanks a million!

On May 18, 11:55 am, justclint  wrote:
> Hey Faza and Rick thanks for your reply. Yes, I am trying to get
> Gender.name. So what Im trying to do is get my array to show up
> something like:
>
> [Product] => Array
>         (
>             [id] => 21
>             [color_id] => 3
>             [image_thumb] => aw_ls_black.png
>             [price] => 27.95
>             [shipping_price] => 5.00
>             [style_id] => 1
>         )
>
>     [Style] => Array
>         (
>             [id] => 1
>             [name] => All Weather Longsleeve Compression Shirt
>
>            [Gender] => Array
>                (
>                  [gender_id] => 2
>                  [gender_name] => Men
>                  )
>             [category_id] => 2
>             [material_id] => 2
>             [application_id] => 2
>
> *Notice the sub array Gender under Style array
>
> I tried doing the "$this->Style->recursive = 1; " and 
> "$this->Product->Style->recursive = 1; " in my products_controller as shown 
> below but
>
> still not getting the correct results.
>
> function view($id = null) {
>                 if (!$id) {
>                         $this->Session->setFlash(__('Invalid Product.', 
> true));
>                         $this->redirect(array('action'=>'index'));
>                 }
>                 $this->Style->recursive = 1;
>                 $this->set('product', $this->Product->read(null, $id));
>
> }
>
> And in my product/view Ive tried echo $product['Gender']['name']
> $product['Style']['Gender.name'] but obviously its showing as an
> unrecognized variable.
>
> Im reading up on the containable right now as I've never used that
> behavior before.
>
> Any additional help would be great. Thanks guys!
>
> On May 18, 6:19 am, Rick  wrote:
>
> > What name are you trying to get?  Looks like you have Style.name
> > already available in your result.
>
> > If there is a Gender.name you are trying to see you can set the
> > recursive to a higher number before the find:
>
> > $this->Style->recursive = 2;
>
> > Or use the Containable behavior as mentioned above.
>
> > On May 17, 5:22 pm, justclint  wrote:
>
> > > Im pulling the data successfully but Im trying to get the "name" value
> > > as opposed to the "id" value in a separate table.
>
> > > When I do debug I get this:
> > > (
> > >     [Product] => Array
> > >         (
> > >             [id] => 21
> > >             [color_id] => 3
> > >             [image_thumb] => aw_ls_black.png
> > >             [price] => 27.95
> > >             [shipping_price] => 5.00
> > >             [style_id] => 1
> > >         )
>
> > >     [Style] => Array
> > >         (
> > >             [id] => 1
> > >             [name] => All Weather Longsleeve Compression Shirt
> > >             [gender_id] => 2
> > >             [category_id] => 2
> > >             [material_id] => 2
> > >             [application_id] => 2
>
> > > For sake of example I will just reference the gender_id. I need it to
> > > show the name not the id.
>
> > > I have the following tables/models.
>
> > > Products
> > > Styles
> > > Genders
>
> > > Product Model:
> > > class Product extends AppModel {
>
> > >         var $name = 'Product';
>
> > >         var $belongsTo = array(
> > >                 'Style' => array(
> > >                         'className' => 'Style',
> > >                         'foreignKey' => 'style_id',
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => ''
> > >                 ),
> > > );
>
> > > }
>
> > > Styles Model:
> > > class Style extends AppModel {
>
> > >         var $name = 'Style';
>
> > >         var $belongsTo = array(
> > >                 'Gender' => array(
> > >                         'className' => 'Gender',
> > >                         'foreignKey' => 'gender_id',
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => ''
> > >                 ),
> > >                 'Category' => array(
> > >                         'className' => 'Category',
> > >                         'foreignKey' => 'category_id',
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => ''
> > >                 ),
> > >                 'Material' => array(
> > >                         'className' => 'Material',
> > >                         'foreignKey' => 'material_id',
> > >                         'conditions' => '',
> > >                         'fields' => '',
> > >                         'order' => ''
> > >                 ),
> > >                 'Application' => array(
> > >                         'className' => 'Application',
> > >                         '

Re: retrieving data from another table

2009-05-18 Thread justclint

Hey Faza and Rick thanks for your reply. Yes, I am trying to get
Gender.name. So what Im trying to do is get my array to show up
something like:

[Product] => Array
(
[id] => 21
[color_id] => 3
[image_thumb] => aw_ls_black.png
[price] => 27.95
[shipping_price] => 5.00
[style_id] => 1
)

[Style] => Array
(
[id] => 1
[name] => All Weather Longsleeve Compression Shirt

   [Gender] => Array
   (
 [gender_id] => 2
 [gender_name] => Men
 )
[category_id] => 2
[material_id] => 2
[application_id] => 2

*Notice the sub array Gender under Style array

I tried doing the "$this->Style->recursive = 1; " and "$this->Product-
>Style->recursive = 1; " in my products_controller as shown below but
still not getting the correct results.

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Product.', true));
$this->redirect(array('action'=>'index'));
}
$this->Style->recursive = 1;
$this->set('product', $this->Product->read(null, $id));

}

And in my product/view Ive tried echo $product['Gender']['name']
$product['Style']['Gender.name'] but obviously its showing as an
unrecognized variable.

Im reading up on the containable right now as I've never used that
behavior before.

Any additional help would be great. Thanks guys!

On May 18, 6:19 am, Rick  wrote:
> What name are you trying to get?  Looks like you have Style.name
> already available in your result.
>
> If there is a Gender.name you are trying to see you can set the
> recursive to a higher number before the find:
>
> $this->Style->recursive = 2;
>
> Or use the Containable behavior as mentioned above.
>
> On May 17, 5:22 pm, justclint  wrote:
>
> > Im pulling the data successfully but Im trying to get the "name" value
> > as opposed to the "id" value in a separate table.
>
> > When I do debug I get this:
> > (
> >     [Product] => Array
> >         (
> >             [id] => 21
> >             [color_id] => 3
> >             [image_thumb] => aw_ls_black.png
> >             [price] => 27.95
> >             [shipping_price] => 5.00
> >             [style_id] => 1
> >         )
>
> >     [Style] => Array
> >         (
> >             [id] => 1
> >             [name] => All Weather Longsleeve Compression Shirt
> >             [gender_id] => 2
> >             [category_id] => 2
> >             [material_id] => 2
> >             [application_id] => 2
>
> > For sake of example I will just reference the gender_id. I need it to
> > show the name not the id.
>
> > I have the following tables/models.
>
> > Products
> > Styles
> > Genders
>
> > Product Model:
> > class Product extends AppModel {
>
> >         var $name = 'Product';
>
> >         var $belongsTo = array(
> >                 'Style' => array(
> >                         'className' => 'Style',
> >                         'foreignKey' => 'style_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 ),
> > );
>
> > }
>
> > Styles Model:
> > class Style extends AppModel {
>
> >         var $name = 'Style';
>
> >         var $belongsTo = array(
> >                 'Gender' => array(
> >                         'className' => 'Gender',
> >                         'foreignKey' => 'gender_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 ),
> >                 'Category' => array(
> >                         'className' => 'Category',
> >                         'foreignKey' => 'category_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 ),
> >                 'Material' => array(
> >                         'className' => 'Material',
> >                         'foreignKey' => 'material_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 ),
> >                 'Application' => array(
> >                         'className' => 'Application',
> >                         'foreignKey' => 'application_id',
> >                         'conditions' => '',
> >                         'fields' => '',
> >                         'order' => ''
> >                 )
> >         );
>
> > }
>
> > Gender Model:
> >         var $name = 'Gender';
>
> >         var $hasMany = array(
>
> >                 'Style' => array(
> >                         'className' => 'Style',
> >                         'foreignKey' => 'gender_id',
> >                         'depende

Re: retrieving data from another table

2009-05-18 Thread Rick

What name are you trying to get?  Looks like you have Style.name
already available in your result.

If there is a Gender.name you are trying to see you can set the
recursive to a higher number before the find:

$this->Style->recursive = 2;

Or use the Containable behavior as mentioned above.




On May 17, 5:22 pm, justclint  wrote:
> Im pulling the data successfully but Im trying to get the "name" value
> as opposed to the "id" value in a separate table.
>
> When I do debug I get this:
> (
>     [Product] => Array
>         (
>             [id] => 21
>             [color_id] => 3
>             [image_thumb] => aw_ls_black.png
>             [price] => 27.95
>             [shipping_price] => 5.00
>             [style_id] => 1
>         )
>
>     [Style] => Array
>         (
>             [id] => 1
>             [name] => All Weather Longsleeve Compression Shirt
>             [gender_id] => 2
>             [category_id] => 2
>             [material_id] => 2
>             [application_id] => 2
>
> For sake of example I will just reference the gender_id. I need it to
> show the name not the id.
>
> I have the following tables/models.
>
> Products
> Styles
> Genders
>
> Product Model:
> class Product extends AppModel {
>
>         var $name = 'Product';
>
>         var $belongsTo = array(
>                 'Style' => array(
>                         'className' => 'Style',
>                         'foreignKey' => 'style_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 ),
> );
>
> }
>
> Styles Model:
> class Style extends AppModel {
>
>         var $name = 'Style';
>
>         var $belongsTo = array(
>                 'Gender' => array(
>                         'className' => 'Gender',
>                         'foreignKey' => 'gender_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 ),
>                 'Category' => array(
>                         'className' => 'Category',
>                         'foreignKey' => 'category_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 ),
>                 'Material' => array(
>                         'className' => 'Material',
>                         'foreignKey' => 'material_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 ),
>                 'Application' => array(
>                         'className' => 'Application',
>                         'foreignKey' => 'application_id',
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => ''
>                 )
>         );
>
> }
>
> Gender Model:
>         var $name = 'Gender';
>
>         var $hasMany = array(
>
>                 'Style' => array(
>                         'className' => 'Style',
>                         'foreignKey' => 'gender_id',
>                         'dependent' => false,
>                         'conditions' => '',
>                         'fields' => '',
>                         'order' => '',
>                         'limit' => '',
>                         'offset' => '',
>                         'exclusive' => '',
>                         'finderQuery' => '',
>                         'counterQuery' => ''
>                 )
>         );
>
> }
>
> ?>
>
> The page im trying to get this on is my product view page. Action
> looks like this:
>
>         function view($id = null) {
>                 if (!$id) {
>                         $this->Session->setFlash(__('Invalid Product.', 
> true));
>                         $this->redirect(array('action'=>'index'));
>                 }
>
>                 $this->set('product', $this->Product->read(null, $id));
>         }
>
> Ive been playing with this for hours and I just cant seem to get it.
>
> If you need more info, please dont hesitate to ask.
>
> 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
-~--~~~~--~~--~--~---



Re: retrieving data from another table

2009-05-17 Thread Faza

Check the Containable behavior.
Helped me alot when I was dealing with complex relations on different 
depths.

http://book.cakephp.org/view/474/Containable

justclint pisze:
> Im pulling the data successfully but Im trying to get the "name" value
> as opposed to the "id" value in a separate table.
>
> When I do debug I get this:
> (
> [Product] => Array
> (
> [id] => 21
> [color_id] => 3
> [image_thumb] => aw_ls_black.png
> [price] => 27.95
> [shipping_price] => 5.00
> [style_id] => 1
> )
>
> [Style] => Array
> (
> [id] => 1
> [name] => All Weather Longsleeve Compression Shirt
> [gender_id] => 2
> [category_id] => 2
> [material_id] => 2
> [application_id] => 2
>
>
> For sake of example I will just reference the gender_id. I need it to
> show the name not the id.
>
> I have the following tables/models.
>
> Products
> Styles
> Genders
>
> Product Model:
> class Product extends AppModel {
>
>   var $name = 'Product';
>
>   var $belongsTo = array(
>   'Style' => array(
>   'className' => 'Style',
>   'foreignKey' => 'style_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   ),
> );
>
> }
>
> Styles Model:
> class Style extends AppModel {
>
>   var $name = 'Style';
>
>   var $belongsTo = array(
>   'Gender' => array(
>   'className' => 'Gender',
>   'foreignKey' => 'gender_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   ),
>   'Category' => array(
>   'className' => 'Category',
>   'foreignKey' => 'category_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   ),
>   'Material' => array(
>   'className' => 'Material',
>   'foreignKey' => 'material_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   ),
>   'Application' => array(
>   'className' => 'Application',
>   'foreignKey' => 'application_id',
>   'conditions' => '',
>   'fields' => '',
>   'order' => ''
>   )
>   );
>
> }
>
> Gender Model:
>   var $name = 'Gender';
>
>   var $hasMany = array(
>
>   'Style' => array(
>   'className' => 'Style',
>   'foreignKey' => 'gender_id',
>   'dependent' => false,
>   'conditions' => '',
>   'fields' => '',
>   'order' => '',
>   'limit' => '',
>   'offset' => '',
>   'exclusive' => '',
>   'finderQuery' => '',
>   'counterQuery' => ''
>   )
>   );
>
> }
> ?>
>
> The page im trying to get this on is my product view page. Action
> looks like this:
>
>   function view($id = null) {
>   if (!$id) {
>   $this->Session->setFlash(__('Invalid Product.', true));
>   $this->redirect(array('action'=>'index'));
>   }
>
>   $this->set('product', $this->Product->read(null, $id));
>   }
>
> Ive been playing with this for hours and I just cant seem to get it.
>
> If you need more info, please dont hesitate to ask.
>
> 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
-~--~~~~--~~--~--~---



retrieving data from another table

2009-05-17 Thread justclint

Im pulling the data successfully but Im trying to get the "name" value
as opposed to the "id" value in a separate table.

When I do debug I get this:
(
[Product] => Array
(
[id] => 21
[color_id] => 3
[image_thumb] => aw_ls_black.png
[price] => 27.95
[shipping_price] => 5.00
[style_id] => 1
)

[Style] => Array
(
[id] => 1
[name] => All Weather Longsleeve Compression Shirt
[gender_id] => 2
[category_id] => 2
[material_id] => 2
[application_id] => 2


For sake of example I will just reference the gender_id. I need it to
show the name not the id.

I have the following tables/models.

Products
Styles
Genders

Product Model:
class Product extends AppModel {

var $name = 'Product';

var $belongsTo = array(
'Style' => array(
'className' => 'Style',
'foreignKey' => 'style_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
);

}

Styles Model:
class Style extends AppModel {

var $name = 'Style';

var $belongsTo = array(
'Gender' => array(
'className' => 'Gender',
'foreignKey' => 'gender_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Category' => array(
'className' => 'Category',
'foreignKey' => 'category_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Material' => array(
'className' => 'Material',
'foreignKey' => 'material_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Application' => array(
'className' => 'Application',
'foreignKey' => 'application_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

}

Gender Model:
var $name = 'Gender';

var $hasMany = array(

'Style' => array(
'className' => 'Style',
'foreignKey' => 'gender_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);

}
?>

The page im trying to get this on is my product view page. Action
looks like this:

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Product.', true));
$this->redirect(array('action'=>'index'));
}

$this->set('product', $this->Product->read(null, $id));
}

Ive been playing with this for hours and I just cant seem to get it.

If you need more info, please dont hesitate to ask.

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
-~--~~~~--~~--~--~---