Hi Maybe you can do this
Country hasMany State State hasMany City Country.city_id (the capital) State.city_id (the capital) I would rather go for Tree behavior. Best regards On 5 ago, 10:43, DerBjörn <[email protected]> wrote: > Hi, > > i have three tables: countries, states and cities. > > Every country has its capital city, so does every state. > 2 relations are very obvious: > > state belongsTo country > city belongs to state > > Now i have a problem to realize the relations referring to the capital > cities. > In my opinion there are two hasOne relations: > > state hasOne city > country hasOne city > > Both tables (states and countries) has a column names city_id as > foreign_key, but if i use two hasOnes like > > [code] > var $hasOne = array( > 'CapitalCity' => array( > 'className' => 'City', > 'foreignKey' => 'city_id', > 'conditions' => '', > 'fields' => '', > 'order' => '' > ) > ); > [/code] > > i get following error message: > [quote]Warning (512): SQL Error: 1054: Unknown column > 'CapitalCity.capitalcity_id' in 'on clause' [CORE/cake/libs/model/ > datasources/dbo_source.php, line 681][/quote] > > [quote]Query: SELECT COUNT(*) AS `count` FROM `countries` AS `Country` > LEFT JOIN `cities` AS `CapitalCity` ON (`CapitalCity`.`city_id` = > `Country`.`id`) WHERE 1 = 1 [/quote] > > Actually it has to be (`CapitalCity`.`id` = `Country`.`city_id`) to > make sense. What i did wrong? > In a forum i asked i ve been told that to realize the capital city > connections i have to use 2 belongsTo relations, but it doesn't make > any sense to me. > > Somebody can enlight me? :) > Thanks! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
