You don't need to set a foreign key in State for City. By adding the
state_id column in your city table you are establishing the hasMany,
State hasMany City, and the belongsTo, City belongsTo State. Just set
the hasMany and belongsTo properly in State and City respectively and
the relationship should work.


On Jul 6, 8:49 pm, varai <[email protected]> wrote:
> Hi,
>
> I am trying to define relationship between state and city.
>
> State hasMany City -- foreign key state_id in City
> City belongsTo State
>
> State fields: id, state_name
> City fields: id, city_name, state_id
>
> but for City belongsTo State, it seems illogically to set a foreign
> key in State coz' then State records will be repeating.
>
> What is the best way to go about this?
>
> thank you.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to