Thanks j,

for your example and your suggestions.
I think I will go with the tinyint. What about the idea to use
is_state_capital and is_capital? Wouldnt this solve the problem?
I am still thinking how to work in my database with an unique key to
get sure that duplicate capitals for one state or country are not
allowed.
The check in the model as you say is a good idea but i prefer to avoid
duplicates with both sides :)
Unique key with state_id and is_capital? For a country that doesnt has
states i could use instead a "fake state" named like the country if i
dont go with the region... Israel -> Isreal -> Tel Aviv.

Can a city be capital of a country and not of its state? I dont think
so. Can it? cause then one tinyint with 1 as state capital and 2 as
capital of country would be enough. and an unique key(state_id,
is_capital)...

Questions over questions :) ... to spin the wheel...

On 24 Aug., 13:44, "j.blotus" <[email protected]> wrote:
> I don't use capitals, but as has been said before, you could create a
> field oncities
>
> 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 othercountriesStates/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 somecountrieswont be set up that way.
> But allcitieswill 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 manycities. 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