On Sep 5, 12:01 pm, Ketan Patel <[EMAIL PROTECTED]> wrote:
> You were on right track for creating a AppReadOnlyModel which extends
> AppModel and overwrite the beforeSave, beforeDelete methods.
>
> There are mistakes with your relations. I think the right relations
> are:
> ZipCode hasOne City
> City hasMany ZipCode
>

You would think so, huh? ;)

In actuality, some zip codes have multiple city names - especially in
rural areas. So, it truly is HABTM.

Some examples:

16617 = Bellwood, PA and Antis, PA
27616 = Raleigh, NC and Brentwood, NC

I was also surprised to learn this.

> Now, that you have all your zipcode, city, state and country model
> extend AppReadOnlyModel, the only thing missing is the distance
> calculation. How are you going to calculate the distance? Is it going
> to be based on the zipcode inputs (11211 to 19232) or city input
> (Austin to Houston). Then depending on this, you have to decide which
> model the function would go for calculateDistance(). I would be
> interested in knowing your implementation as I might do something
> similar in future.
>

I've done the radius calculation before. I would be doing it from zip
code to zip code. I would also have other function hooks such as
getZipCodesByCity(), getCitiesByZipCode(), getStateByCity(), etc.

If you want to know how to do the calculation itself I could help you
out there. I will most likely be implementing some caching mechanism
for these calculations, as well, since they are rather intensive. I
just want to setup the object model properly before I worry about
that, however.

If I can make this a component that is portable, I would be more than
happy to throw it up on the bakery.

> Ketanhttp://www.eclassifieds4u.com
>
> Jason wrote:
> > This is my first post to this group, so I'd like to say hello
> > first. :) This post seems long, but the question is pretty simple -
> > not sure about the answer.
>
> > My question revolves around models. I have 5 tables that represent
> > geographic information. I want to use this to do radius searches among
> > other things.
>
> > My problem is I'm not sure how to represent this data within Cake. My
> > tables are setup as follows:
>
> > zip_codes
> >     zip_code
> >     latitude
> >     longitude
> >     dst (daylights saving - boolean)
> >     timezone
>
> > cities
> >     id
> >     state_id
> >     name
>
> > cities_zip_codes
> >      city_id
> >      zip_code
>
> > states
> >     id
> >     country_id
> >     name
>
> > countries
> >     id
> >     name
>
> > I would like to be able to access this data through one object that is
> > locked down. There will be no reason for my application to ever add or
> > delete from these tables. I was hoping that I could create something
> > sort of like a Component is to a controller or a helper is to a view
> > for a model. Nothing like this seems to exist, however.
>
> > If I were to use Cake's built in ORM, it would be as follows:
>
> > zip_code has and belongs to many city
> > city has and belongs to many zip_code, city belongs to state
> > state has many city, state belongs to country
> > country has many state
>
> > Using it this way, which model would I then use? How do I keep coders
> > from using these models to edit the tables? Isn't this a LOT of
> > queries everytime I instantiate one of these models? And scaffolding
> > totally blows up (spikes my Apache process to 100% and doesn't let go)
> > when I attempt to use this type of ORM.
>
> > I need a way to have an object talk to these tables and provide me
> > with the few functions I need (distance between two zip codes, radius
> > searching, etc.) without providing full ORM. I also need to be able to
> > access this object from within any controller and it needs to use the
> > DB connection that Cake sets up.
>
> > What is the best way to accomplish this while staying within the
> > constraints and guidelines of the Cake system?
>
> > Any suggestions are GREATLY appreciated!
>
> > Thanks,
>
> > Jason


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to