need to define a with key and include the name of the Join model. It was a bug that auto loaded the model in the past for you.
-Mark On Jan 8, 6:17 pm, bunwich <[email protected]> wrote: > Hi, > I've been playing with 1.2 final and was having problems calling ->find > ('all') on a HABTM join table. By convention you don't create a > AppModel .php file for a Join table in a HABTM relationship, but since > i had specific queries i needed to make, the file was created. > > In simple terms A and C have a HABTM relationship and they both use B > as the join table. > > I then have a method within B that is called like this: > $this->A->B->foo()); > > This worked in one of the RC's, but doesn't any more in the final. I > have an inkling why it should or shouldn't, but maybe someone can shed > some light on this: > > ****** Example ***** > // has fields (id, name) > class User extends AppModel { > var $hasAndBelongsToMany = array('Car'); > > } > > // has fields (id, name) > class Car extends AppModel { > var $hasAndBelongsToMany = array('User'); > > } > > // has fields (user_id, car_id, role_id) > class UsersCar extends AppModel { > var $belongsTo = array('User', 'Car'); > > function getAllOwners() > return $this->find('all', array('conditions' => array > ('UserCar.role_id' => 3)); > } > > } > > *** Error *** > In previous RC's I was able to call sub methods > pr($this->User->UsersCar->getAllOwners()); > > In 1.2 Final I get this error. > > Warning (512): SQL Error: 1064: You have an error in your SQL syntax; > check the manual that corresponds to your MySQL server version for the > right syntax to use near 'fuck' at line 1 [CORE\cake\libs\model > \datasources\dbo_source.php, line 514] > > Query: getAllOwner > > *** Problem *** > What appears to be happening is that UsersCar doesn't get > automatically instantiated when the HABTM relationship is > created...maybe :) > > *** The workaround *** > in > class User extends AppModel { > var $hasAndBelongsToMany = array('Car'); > var $hasMany = array('UsersCar'); // this is now required in > 1.2 Final > > } > > So I can see why this is necessary, as it was assumed the Join Table > was instantiated when the HABTM was declared. In previous RC's it was > assumed that UsersCar was instantiated if User had a HABTM to Car. > > One other note from the other postings that I've been reading, do I > need to know add a primary key to the Join Table UsersCar? (ie a new > field called 'id') > > Any comments would be appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" 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?hl=en -~----------~----~----~----~------~----~------~--~---
