I don't use capitals, but as has been said before, you could create a
field on cities

TINYINT(1) is_capital

it would be a simple 0 for not capital, 1 for capital

My model works well for USA.
EX.

North America (Zone) ->
United States (Country) ->
Florida (State) ->
North Florida (Region) ->
Tallahassee (City) and it could be capital since it is state capital

For other countries States/Regions become a bit difficult so you might
have something like this:
Middle East (Zone) ->
Israel (Country) ->
Tel Aviv (City) and is_capital = 1

So in that case you may not have a state or region.

The important thing in your city model is that region_id and state_id
can be null, because some countries wont be set up that way.
But all cities will have at least a zone and a country. You might not
even use zone if you dont have a need for organizing it.

As far as preventing duplicate capitals, you can create a validation
rule in your City model that checks to see if a capital already
exists, and prevent save if one does.

Hope this helps get your wheels spinning a bit.

On Aug 24, 8:40 am, DerBjörn <[email protected]> wrote:
> Hi J.Blotus,
>
> City belongsTo State, cause a state as many cities. Thats right.
> First i had State/City hasOne City/State to realize a state capital,
> but i have been told that hasOne doesn't work here and i have to use
> belongsTo instead...
> I always was with doubts about it, but i read this suggestion not only
> in this group...
>
> I am very interested in your region app. It does make sense of course,
> but you are able to realize capitals with it? A city has to be able to
> be a capital of a state or a country. How do you manage it? How look
> your tables?
>
> Thanks
>
> On 23 Aug., 20:15, "j.blotus" <[email protected]> wrote:
>
>
>
> > How does State belongTo City? Isn't it the other way around? Same with
> > Country.
>
> > On my region based apps I use the following
>
> > Zone hasMany Country, State, Region, City
> > Country hasMany  State, Region, City
> > State hasMany Region, City
> > Region hasMany City
>
> > Country belongsTo Zone
> > State belongsTo Zone, Country
> > Region belongsTo Zone, Country, State
> > City belongsTo Zone, Country, State, Region
>
> > Zone is North America, South America, Asia, Etc
>
> > On Aug 18, 5:17 pm, DerBjörn <[email protected]> wrote:
>
> > > Thanks, Dan!
>
> > > After I rebaked my models with following relations:
>
> > > City belongsTo State
>
> > > State belongsTo Country
> > > State belongsTo City
> > > State hasMany City
>
> > > Country belongsTo City
> > > Country hasMany State
>
> > > and updated my views, finally i got a "result"...
> > > Your advice with "containable" i haven't follow till now.
>
> > > I still have one problem that maybe i am able to solve with cricket's
> > > advice of using virtual models!?!
> > > When i want to add p.e. a new country or a new state, their comboboxes
> > > for capital city are empty, so i cannot choose its capital city. How
> > > do I solve this problem?
> > > Thanks a lot :)

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

Reply via email to