In case someone else wants to avoid spending an afternoon inside the ClassRegistry. Here is the wisdom I was lacking:
When specifying "with" for a HABTM... you MUST specify this on both ends of the association. You can not use the "less changes = less errors" and start by trying to get one side (A->B) correct and then fill in the other side when it works from the first side. This is because if Cake chooses to load Class B first (even though I am in ControllerA and A tops B alphabetically) the registry will have created an AppModel called AB (joining model) and when A loads, that Class is reused (as it should). In a word: GAAAAAARRRRGHGHHH!!! It may sound dumb as h*** but it took me hours trawling line for line through Model, ClassRegistry and App before I figured this out. I don't know how my associated model managed to load first but I think I'll leave it here and get on with something productive. Keep Baking! /Martin On Jan 15, 8:42 am, Martin Westin <[email protected]> wrote: > Sure. This is from the NewsMessage side of things > > var $hasAndBelongsToMany = array( > 'NewsSubscriber' => array( > 'className' => 'News.NewsSubscriber', > 'joinTable' => 'news_messages_news_subscribers', > 'with' => 'News.NewsMessagesNewsSubscriber', > 'foreignKey' => 'news_message_id', > 'associationForeignKey' => 'news_subscriber_id', > 'conditions' => '', > 'order' => '', > 'limit' => '', > 'unique' => true, > 'finderQuery' => '', > 'deleteQuery' => '', > 'insertQuery' => '' > ) > ); > > I have tried removing the "News." prefix. > I have tried putting the join model in the "root" application. > (just to make see if anything happened) > > /Martin > > On Jan 14, 10:57 pm, Webweave <[email protected]> wrote: > > > Can you post your HABTM from your models ? > > > It looks like you have the model file in the right place, so my guess > > is that the problem is in there. > > > On Jan 14, 4:59 am, Martin Westin <[email protected]> wrote: > > > > Hi everyone, > > > > This is the first time I have tried to make a real model for a joining > > > table and I got really stuck on this seemingly simple thing. I just > > > cant get it to work. Does anyone know how this file should be named? > > > > I have a HABTM association between two models in a plugin. I have now > > > created a joining model to be able to capture some callbacks and write > > > custom "behaviours". Problem is Cake does not load the model but > > > resorts to creating its magic "empty" model based on AppModel. It does > > > not even seem to find the model's file. > > > > The facts: > > > > News.NewsMessage habtm News.NewsSubscriber > > > > --- among other things in NewsMessage > > > 'with' => 'News.NewsMessagesNewsSubscriber', > > > --- > > > > --- NewsMessagesNewsSubscriber > > > debug('NewsMessagesNewsSubscriber file was loaded'); > > > class NewsMessagesNewsSubscriber extends NewsAppModel { > > > var $name = 'NewsMessagesNewsSubscriber'; > > > function afterFind() { > > > debug('NewsMessagesNewsSubscriber class was used in a find'); > > > }} > > > > --- > > > > I have but debug lines straight into the model file to see if it loads > > > at all and nothing. So I guess I have to name it something special I > > > can't figure out. > > > > I have tried the following files placed in app/plugins/news/models/ > > > news_messages_news_subscriber.php <-- should be this one, right? > > > news_message_news_subscriber.php > > > news_messages_news_subscribers.php > > > > If you know what I should call this file, please reply while I have a > > > few hairs left on my head ;) > > > thanks > > > > Martin Westin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
