1. Add $primaryKey = 'zip'; in Zipcode model. 2. Define 'foreignKey'=>'zip' in $hasMany association. 3. Your associations should looks like: User belogsTo Zip, Zip hasMany Users.
On Dec 4, 9:02 am, Jon Hinson <[EMAIL PROTECTED]> wrote: > Ok, I can't seem to solve this problem for the life of me. I have a > User model and a Zipcode model. Zipcode hasMany users. I want them to > join on User.zip = Zipcode.zip. I have to join on Zipcode.zip and not > Zipcode.id because a zipcode can have many rows because of several > city names, etc. I know this is not normalized, but it is much easier > like this. So I have a hasMany association that looks like this: > > var $hasMany = array('User' => > array('className' => 'User', > 'conditions' => '', > 'order' => '', > 'dependent' => true, > 'foreignKey' => '', > 'finderQuery' => ' > SELECT * > > FROM users as User > > JOIN zipcodes as Zipcode ON (User.zip = Zipcode.zip)' > ) > ); > > I tried using the finderQuery after doing foreignKey => 'zip' didn't > work. I also had a belongsTo Zipcode in User with foreignKey => > 'zip' : > > var $belongsTo = array('Zipcode' => > array('className' => 'Zipcode', > 'conditions' => '', > 'order' => '', > 'dependent' => true, > 'foreignKey' => > 'zip' > ) > ); > > With everything that I've tried, when I do a $this->Zipcode->User->findAll, > or try to paginate with $this->Zipcode->User, it tries to > > join on User.zip = Zipcode.id instead of Zipcode.zip. > > Any help is much appreciated. > Jon > > PS- I'm using Cake 1.2 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" 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 -~----------~----~----~----~------~----~------~--~---