If I am not mistaken, I believe the State model has to have an association with RegisteredState model as well to get that backwards compatibility. Take a look at the user and profile models in this example.
http://manual.cakephp.org/chapter/models If you notice, User hasOne Profile while Profile belongsTo User. There is a definition in both models to get the expected return and association. I don't know exactly what you are trying to accomplish but, if you do a hasAndBelongsToMany, don't forget to make the Join table with the name registered_states_states and just have two columns, one with registered_state_id and the other with state_id. Tell me if this helps you any or, you can post back with what exactly you are trying to do and how you envision the relationship between state and registered_state. Are they sort of "tags" as in State: Open, Closed? or Something else? In all, the only problem I can see right now with your code is you do not have the backwards association in the State model. Try belongsTo. On Feb 11, 10:21 am, "Erich C. Beyrent" <[EMAIL PROTECTED]> wrote: > Here are my tables: > > CREATE TABLE `registered_states` ( > `state_id` int(11) NOT NULL default '0', > PRIMARY KEY (`state_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 > > CREATE TABLE `states` ( > `id` int(11) NOT NULL auto_increment, > `name` varchar(24) NOT NULL default '', > `code` char(2) NOT NULL default '', > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 > > Models: > > // registered_state.php > class RegisteredState extends AppModel > { > var $name = 'RegisteredState'; > > var $hasMany = array('State' => > array('className' => 'State', > 'conditions' => '', > 'order' => '', > 'limit' => '', > 'foreignKey' => 'state_id', > 'dependent' => false, > 'exclusive' => false, > 'finderQuery' => '' > ) > ); > > } > > // state.php > class State extends AppModel > { > var $name = 'State'; > var $validates = array('code' => VALID_NOT_EMPTY); > > } > > -Erich- > > Christopher E. Franklin, Sr. wrote: > > > Post your model code with the names of the files and where they are > > located. > > > On Feb 10, 6:12 pm, "Erich C. Beyrent" <[EMAIL PROTECTED]> > > wrote: > >> That did not work - now I get: > > >> Array > >> ( > >> [0] => Array > >> ( > >> [RegisteredState] => Array > >> ( > >> [state_id] => 10 > >> ) > > >> [State] => Array > >> ( > >> ) > > >> ) > >> ) > > >> I know I can write my own custom query for this, but I am unsure as to > >> why this isn't working for me. > > >> -Erich- > > >> djiize wrote: > >>> in registered_states table, try state_id (not plural) > >>> On 9 fév, 19:10, "Erich C. Beyrent" <[EMAIL PROTECTED]> wrote: > >>>> I am trying to link two tables, states and registered_states. > >>>> The states table has id, name, and code as fields, and registered_states > >>>> has states_id. > >>>> I defined as hasMany association in the registered_states model, and now > >>>> want to produce a list of all the registered states and their associated > >>>> state. > >>>> I'm getting the list of registered states, but no state data: > >>>> Array > >>>> ( > >>>> [0] => Array > >>>> ( > >>>> [RegisteredState] => Array > >>>> ( > >>>> [states_id] => 10 > >>>> ) > >>>> [State] => Array > >>>> ( > >>>> ) > >>>> ) > >>>> ) > >>>> What I'm particularly interested in retrieving is the state code for > >>>> each registered state. > >>>> How can I accomplish this? > >>>> -Erich- --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
