Re: Help with table relationships

2008-12-09 Thread [EMAIL PROTECTED]



Thanks guys! Your advice was definitely helpful
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Help with table relationships

2008-12-08 Thread Milmar

I suggest you try the bake feature to generate the codes to minimize
any syntax issues.
About hasMany, it has other parameters that might need to be set, and,
I think you cannot define multiple hasMany variables (just put all
related models in an array).

e.g.

class User extends AppModel {
var $name = 'User';
var $hasMany = array(
   'Article' = array('className' = 'Article',
   'foreignKey' = 'user_id',
   'dependent' = false,
   'conditions' = '',
  ... some other parameters...
  ),
  'Event' = array('className' = 'Event',
  ...other parameters...
  )
);


Note that this will be automatically generated when you use the bake
feature.


On Dec 8, 1:53 pm, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I'm building a basic CMS and I have a 'users' table that is related to
 more than one other table. The 'users' table is related to these other
 tables by a '$hasMany' relationship. I did the bare minimum in terms
 of setting up my models and databases using the $scaffold feature so I
 could be sure everything worked before getting in too deep. Cake set
 everything up for me nicely except for anything having to do with my
 'users' table which is related to a bunch of other tables in a
 $hasMany relationship. I'm pretty new to PHP so I'm not sure if I just
 have a syntax problem or if PHP doesn't allow one table to have more
 than one $hasMany relationship. Here is the model code I am having
 trouble with:

 ?php

 class User extends AppModel {
         var $name = 'User';
         var $hasMany = array('Article');
         var $hasMany = array('Event');
         var $hasMany = array('Post');
         var $hasMany = array('Price');
         var $hasMany = array('Upload');

 }

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



Re: Help with table relationships

2008-12-08 Thread WebbedIT

The issue is that you are overwriting the $hasMany array with each new
declaration so only the last hasMany relationship will be created
(Upload).  As Milmar says you need to group multiple relation types
into a single array as follows:

  var $hasMany = array('Article', 'Event', 'Post', 'Price',
'Upload');

However over time you will almost certainly need to expand on these
relationship declarations and include extra parameters (as Milmar
shows above) to eliminate the fetching of extra unwanted data which
may slow your app down.  Takes a while to get your head around but it
eventually all falls into place and makes perfect sense.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---