rnady wrote:
> [EMAIL PROTECTED] wrote:
> > Use the associations.  Then you can return it with
> > $data['Importance']['importance'].
> >
> > I would imagine this could be quickly accomplished with a belongsTo
> > association.
> >
> > http://manual.cakephp.org/chapter/models
>
> Thanks for your response.I know this should be simple and I feel dumb
> because I can't get it to work.  In my importance.php model I added:
> var $belongsTo = array('Item' =>
>                            array('className'  => 'Item',
>                                  'conditions' => '',
>                                  'order'      => '',
>                                  'foreignKey' => 'importances_id'
>                            )
>                      );
>
> I already had this in my Item.php model:
> var $hasMany = array('Importance' =>
>                         array('className'    => 'Importance',
>                               'conditions'   => '',
>                               'order'        => '',
>                               'dependent'    =>  true,
>                               'foreignKey'   => 'importances_id'
>                         )
>                   );
> After adding the belongsTo in my importance model and
> $data['Importance']['importance'] in my view.thtml I get this error:
> Notice: Undefined index: importance in
> N:\www\cake\app\views\items\view.thtml on line 5
> What am I doing wrong?

Mady,

I believe that part of your problem is that you have the associations
backwards.  "Items" belongsTo "Importance"  and "Importance" hasMany
"Items"

The relationship is a one-to-many with each Importance level having
possibly many related items but each Item can only have one importance
level.  Try switching the two and see if that helps... like so:

In item:

var $belongsTo = array('Importance' =>
                            array('className'  => 'Importance',
                                  'conditions' => '',
                                  'order'      => '',
                                  'foreignKey' => 'importances_id'
                            )
                      );




In Importance:

var $hasMany = array('Item' =>
                         array('className'    => 'Item',
                               'conditions'   => '',
                               'order'        => '',
                               'dependent'    =>  true,    //<-- Note:
this probably should be false unless you intend for the related items
to be deleted if you delete an importance level.
                               'foreignKey'   => 'importances_id'
                         )
                   );

Hope that helps!

jonlb


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to