Re: Complex table relationship within one model

2007-09-07 Thread AD7six



On Sep 7, 6:35 am, Jason <[EMAIL PROTECTED]> wrote:

> The reason for "why" in my mind is bloat. Why go through the process
> of loading an entire ORM object when all you want is read-only access?
> I think a read only model type with all the fat trimmed would be a
> nice addition. Maybe I'm alone there..

I don't understand from where the idea comes from that read only
access == a simpler model. The difference would only be the absence of
the method save and related empty callbacks. Almost all of cake's
model code relates to reading the right data.

However, as with any suggestion, if you create a ticket on
trac.cakephp.org with a patch it would be at least get some visibility
and be considered.

hth,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-06 Thread Jason



On Sep 6, 4:02 am, AD7six <[EMAIL PROTECTED]> wrote:
> Hi Jason,
>
> Sorry, somethings (How do I keep coders from using these models to
> edit the tables?) lead me to believe you were asking a (internal?)
> security question. And sorry if that tainted the tone of my reply.
>

Aye, I could have been more clear. :)

> > It's not so much a security thing as it is a confusion thing. Cake
> > really should have a read only model structure.
>

The reason for "why" in my mind is bloat. Why go through the process
of loading an entire ORM object when all you want is read-only access?
I think a read only model type with all the fat trimmed would be a
nice addition. Maybe I'm alone there..


> Irrespective of the behind the scenes stuff, what you want is a (data
> manipulation object) model not a (reusable controllererette)
> component. To access it everywhere you would put var $uses =
> array(NameOfModel); in your app controller
>
> Even if it was setup like this:
>
> class GeoModel extends AppModel {
>  var $useTable = false;
> ...
>   // Define $this->City etc to be an instance of the correct model.
> ...
>  function citiesByZip($zipCode) {
>   // Seehttp://groups.google.com/group/cake-php/web/frequent-discussions
>   // How to handle tricky HasAndBelongsToMany situations?
>   ...
>   $this->City->zipCode->recursive = -1;
>   $zipData = $this->City->ZipCode->findByZipCode($zipCode);
>   $zipCodeID = $zipData['Zipcode']['id'];
>   $this->City->recursive = 0;
>   return $this->City->findAll(Array('CityZip.zip_id' => $zipCodeId));
>
> }

I agree. $usesTable was not something I was aware existed. RTFM, eh?
In that case I can write my own custom SQL and not have to rely on
Cake for these relationships. It's not that Cake CAN'T do this, I just
know that what I want out of these tables is very specific and Cake's
ORM is way too bloated for it with its internal reflection and
relationships. It just isn't efficient. Being able to use a model
without Cake automatically associating it  to a table, however, is
pretty much what I want. As I said previously, being able to have a
trimmed down read-only version of this would be more ideal, this will
certainly suffice.

>
> > > > Using it this way, which model would I then use? How do I keep coders
> > > > from using these models to edit the tables?
>
> You need only define beforeSave and beforeDelete to return false in
> either the behavior they are all using, or in the models themselves or
> in the abstract class they all inherit from.
>

Aye, the behavior works nice for this implementation now that I
understand it a bit more.


> You don't need the $uses declaration. but your controller /should/ be
> called ZipCodesController
>
>
>
> > 4 models
> >  ZipCode (HABTM City)
> >  City (HABTM ZipCode, BelongsTo State)
> >  State (HasMany City, BelongsTo Country)
> >  Country (HasMany State)
>

Actually, I mistyped here. The controller was setup correctly and
$uses is there because I was experiementing with differnet models and
didn't feel like creating a new controller just for the scaffolding
while I was trying to track down why Apache was exploding.

> > That's it. If I navigate to /ZipCode Apache explodes. Any
> > suggestions?
>
> Do you have a full db and are using 1.1? If so the reason is the
> initial index lists with no limit.
>
> You'd need to know the reason for the exploding. Probably there is a
> loop somewhere, and if there is it's either (just guesses)
> 1) A loop somewhere, possibly due to (incorrect) model definitions
> 2) You have all your data in place and have not put a limit in the
> model definition for the number of associated objects to return, as
> such apache is returning a list of zip codes for the index, all
> associated Cities, all secondary associated ZipCodes with no limit
> etc.
>
> First ensure that your code is following 
> conventionshttp://manual.cakephp.org/appendix/conventions
> Try commenting all your association definitions in the models and
> uncomment them one by one to find the reason. Although frustrating
> that sort of problem always has a tangible and fixable reason.
>

It seems to be specific to the PHP and Apache version I had. I am
runnig this for now on a WAMP install (wampserver.com) and I just
upgraded to the newest version. After doing that the scaffolding is
working. :)

>
> Retrieving data -> Model. Custom functionality -> model functions.
> Which model however is up to you and your design.
>
> A component would be the wrong place for your data retrieval logic IMO
> (since for one, you would need to then instantiate a model of some
> kind or another to get the data).
>
> Anyway, hth,
>
> AD

I appreciate the advice (all of you).. I'll simply define a Geo model
that doesn't have any automatic associations to tables.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@google

Re: Complex table relationship within one model

2007-09-06 Thread AD7six

Hi Jason,

Sorry, somethings (How do I keep coders from using these models to
edit the tables?) lead me to believe you were asking a (internal?)
security question. And sorry if that tainted the tone of my reply.

On Sep 6, 12:23 am, Jason <[EMAIL PROTECTED]> wrote:

> It's not so much a security thing as it is a confusion thing. Cake
> really should have a read only model structure.

Why? It's trivial to do with a behavior anyway (1.2 only) and almost
as easy in 1.1.


> I want something to act as a single object
> that I can call upon to get the information I need out of this
> grouping of tables. I want it to be something more specialized than a
> general model.

Irrespective of the behind the scenes stuff, what you want is a (data
manipulation object) model not a (reusable controllererette)
component. To access it everywhere you would put var $uses =
array(NameOfModel); in your app controller

Even if it was setup like this:

class GeoModel extends AppModel {
 var $useTable = false;
...
  // Define $this->City etc to be an instance of the correct model.
...
 function citiesByZip($zipCode) {
  // See http://groups.google.com/group/cake-php/web/frequent-discussions
  // How to handle tricky HasAndBelongsToMany situations?
  ...
  $this->City->zipCode->recursive = -1;
  $zipData = $this->City->ZipCode->findByZipCode($zipCode);
  $zipCodeID = $zipData['Zipcode']['id'];
  $this->City->recursive = 0;
  return $this->City->findAll(Array('CityZip.zip_id' => $zipCodeId));
}


> > > Using it this way, which model would I then use? How do I keep coders
> > > from using these models to edit the tables?

You need only define beforeSave and beforeDelete to return false in
either the behavior they are all using, or in the models themselves or
in the abstract class they all inherit from.


> I HOPE I have something setup wrong, but it just doesn't seem to play
> well with this setup.
>
> Cake 1.2 (latest build)
>
> 1 controller
>  ZipCodeController - scaffolding turned on, $uses ZipCode

You don't need the $uses declaration. but your controller /should/ be
called ZipCodesController

>
> 4 models
>  ZipCode (HABTM City)
>  City (HABTM ZipCode, BelongsTo State)
>  State (HasMany City, BelongsTo Country)
>  Country (HasMany State)
>
> That's it. If I navigate to /ZipCode Apache explodes. Any
> suggestions?

Do you have a full db and are using 1.1? If so the reason is the
initial index lists with no limit.

You'd need to know the reason for the exploding. Probably there is a
loop somewhere, and if there is it's either (just guesses)
1) A loop somewhere, possibly due to (incorrect) model definitions
2) You have all your data in place and have not put a limit in the
model definition for the number of associated objects to return, as
such apache is returning a list of zip codes for the index, all
associated Cities, all secondary associated ZipCodes with no limit
etc.

First ensure that your code is following conventions
http://manual.cakephp.org/appendix/conventions
Try commenting all your association definitions in the models and
uncomment them one by one to find the reason. Although frustrating
that sort of problem always has a tangible and fixable reason.

> Once again, I agree that when it comes down to actual security the
> database is the place. But just to reiterate, it's for clarification
> from a code cleanliness standpoint - much like properly using private/
> public/protected namespaces - that is my intention here. Also, the
> intention of having it be compact.
>
> Maybe there is simply no good answer. I only raise the question.

Retrieving data -> Model. Custom functionality -> model functions.
Which model however is up to you and your design.

A component would be the wrong place for your data retrieval logic IMO
(since for one, you would need to then instantiate a model of some
kind or another to get the data).

Anyway, hth,

AD



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Copongcopong

The Model::bindModel()/unbindModel() is listed in the cakephp manual
http://manual.cakephp.org/chapter/models (latter part) or the api
http://api.cakephp.org/1.2/class_model.html#0b969d5264205cd3a425980dd53e9658

this a way to alter the associations (hasOne, hasMany ...) on the fly.
This will make it sure that you can remove unwanted sql joins or
queries due to the associations that was created for the model/s.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Jason



On Sep 5, 5:17 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Sep 4, 5:32 pm, Jason <[EMAIL PROTECTED]> wrote:
> 
>
>
>
> > 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.
>
> You cannot do anything within Cake to prevent the code 
> $this->Model->query("Update other_table SET x = y") from working, or if 
> someone
>
> wanted to really cheat from using native PHP db functions.
>
> Why don't you just remove privileges for the application's database
> user to update or delete from (or truncate) these tables once set up?
>

It's not so much a security thing as it is a confusion thing. Cake
really should have a read only model structure. Why give the developer
the gun if all he can do is aim it at his head? The argument you're
giving me reminds me of arguments people have given me against public/
private/protected name spaces - some people think they aren't worth
anything. It's not SECURITY, but it does prevent mistakes and it does
implicitly provide clarity on how something should be used.

> > 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.
>
> Behaviors ;) you could create one with beforeDelete and beforeSave
> returning false. But this is the wrong place for such logic imo.
>

You're taking the comment ouf of context a bit. I don't want a
component/helper/behavior to create a read only model. That is clearly
the wrong implementation. I want something to act as a single object
that I can call upon to get the information I need out of this
grouping of tables. I want it to be something more specialized than a
general model. I want to be able to instantiate some sort of Geo
object and ask it questions such as what cities are in this zip code
or what is the distance between these two zip codes. I don't want to
have to manage multiple models for one main task - geography. This
normalized table structure does not lend itself too nicely to Cake's
conventions for ORM and really doesn't need all the overhead the ORM
implementation has if I really only need to read from it.

> > 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?
>
> The model methods acts upon it's own table only with a few notable
> exceptions (cascading deletes but most importantly query() can be used
> for anything).
>

I realize that, but this is confusing. I now have 4 models to choose
from in order to provide the functionality I need instead of one
compact object that does everything Geo-related. Unlike typical Cake
implementations where the complex ORM makes sense, in this case it
makes no sense. The rest of my project fits perfectly within the Cake
conventions, however.

> > 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.
>
> Then something isn't set up correctly.
>

I HOPE I have something setup wrong, but it just doesn't seem to play
well with this setup.

Cake 1.2 (latest build)

1 controller
 ZipCodeController - scaffolding turned on, $uses ZipCode

4 models
 ZipCode (HABTM City)
 City (HABTM ZipCode, BelongsTo State)
 State (HasMany City, BelongsTo Country)
 Country (HasMany State)

That's it. If I navigate to /ZipCode Apache explodes. Any
suggestions?


> > 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.
>
> That's explained in the manual (var $uses in the model chapter).
>

$uses is a controller property, not a model property. $useTable is the
model property, and it is a string not an array. It's meant to allow
the use of a table that doesn't follow cake naming conventions, not
for allowing a model to talk to more than one table at once.


> > What is the best way to accomplish this while staying within the
> > constraints and guidelines of the Cake system?
>
> By following conventions and putting your "you can't touch these
> tables" logic in the right place: the database.
>
> hth,
>
> AD

Once again, I agree that when it comes down to actual security the
database is the place. But just to reiterate, it's for clarification
from a code cleanliness standpoint - much like properly using private/
public/protected namesp

Re: Complex table relationship within one model

2007-09-05 Thread AD7six



On Sep 4, 5:32 pm, Jason <[EMAIL PROTECTED]> wrote:

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

You cannot do anything within Cake to prevent the code $this->Model-
>query("Update other_table SET x = y") from working, or if someone
wanted to really cheat from using native PHP db functions.

Why don't you just remove privileges for the application's database
user to update or delete from (or truncate) these tables once set up?

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

Behaviors ;) you could create one with beforeDelete and beforeSave
returning false. But this is the wrong place for such logic imo.

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

The model methods acts upon it's own table only with a few notable
exceptions (cascading deletes but most importantly query() can be used
for anything).

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

Then something isn't set up correctly.

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

That's explained in the manual (var $uses in the model chapter).

> What is the best way to accomplish this while staying within the
> constraints and guidelines of the Cake system?

By following conventions and putting your "you can't touch these
tables" logic in the right place: the database.

hth,

AD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Jason



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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Ketan Patel

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

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.

Ketan
http://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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread majna

..and use cache for models with cache() function. (states,
countries..)


On Sep 5, 5:16 pm, "Mike Griffin" <[EMAIL PROTECTED]> wrote:
> On 05/09/07, Jason <[EMAIL PROTECTED]> wrote:
>
>
>
> > Even if I don't create the CRUD functionality, it's still there for
> > another developer to totally mess things up. To add some level of
> > protection I've created an AppReadOnlyModel that extends AppModel
> > which has overridden save and delete functionality. It was easier than
> > editing the beforeSave and beforeDelete callbacks of every model I
> > wanted to make readonly.
>
> That seems a little bit like overkill.  If you can't trust your
> developers, who can probably remove the extra checks you have put in
> place if they have access to create CRUD functions in your code, then
> don't let them develop at all.  Sorry if I am not understanding you
> properly here, or jumping to conclusions.
>
> > Could you elaborate a little bit on the bind,unbind functionality and
> > how it could be used here? Or point me in the direction I need to go
> > in the vast internets to find said functionality? Unfortunately I'm
>
> I have written a little bit about the unBindModel in my blog, which
> might help you 
> out:http://griffinm.wordpress.com/2007/06/15/using-unbindmodel-in-cakephp/
> What it does is remove un-needed associations to speed up the database
> queries.  bindModel works in the same way if you want to temporarily
> add more associations.
>
> Mike.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Mike Griffin

On 05/09/07, Jason <[EMAIL PROTECTED]> wrote:
>
> Even if I don't create the CRUD functionality, it's still there for
> another developer to totally mess things up. To add some level of
> protection I've created an AppReadOnlyModel that extends AppModel
> which has overridden save and delete functionality. It was easier than
> editing the beforeSave and beforeDelete callbacks of every model I
> wanted to make readonly.

That seems a little bit like overkill.  If you can't trust your
developers, who can probably remove the extra checks you have put in
place if they have access to create CRUD functions in your code, then
don't let them develop at all.  Sorry if I am not understanding you
properly here, or jumping to conclusions.

> Could you elaborate a little bit on the bind,unbind functionality and
> how it could be used here? Or point me in the direction I need to go
> in the vast internets to find said functionality? Unfortunately I'm

I have written a little bit about the unBindModel in my blog, which
might help you out:
http://griffinm.wordpress.com/2007/06/15/using-unbindmodel-in-cakephp/
What it does is remove un-needed associations to speed up the database
queries.  bindModel works in the same way if you want to temporarily
add more associations.

Mike.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Jason

Even if I don't create the CRUD functionality, it's still there for
another developer to totally mess things up. To add some level of
protection I've created an AppReadOnlyModel that extends AppModel
which has overridden save and delete functionality. It was easier than
editing the beforeSave and beforeDelete callbacks of every model I
wanted to make readonly.

Copong,

Could you elaborate a little bit on the bind,unbind functionality and
how it could be used here? Or point me in the direction I need to go
in the vast internets to find said functionality? Unfortunately I'm
using cake 1.2 which, while it does have an api, does not have any
contextual manual written for it yet (to my knowledge). I don't
remember this functionality being in 1.1.

Thanks again!


On Sep 5, 6:22 am, Copongcopong <[EMAIL PROTECTED]> wrote:
> first, do the 1 table 1 model as suggested.
>
> > I need a way to have an object talk to these tables ...
>
> A Component will surely help on this. have this component (e.g.
> GeoComponent) load the Models during initialization
> Component::__construct().
> You may create different methods/functions for accessing the
> information from the Models.
> You may also prefer to use Model::bindModel()/Model::unbind() feature
> so that you can dynamically alter the tables' association to minimize
> table joins/queries.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Copongcopong

first, do the 1 table 1 model as suggested.

> I need a way to have an object talk to these tables ...

A Component will surely help on this. have this component (e.g.
GeoComponent) load the Models during initialization
Component::__construct().
You may create different methods/functions for accessing the
information from the Models.
You may also prefer to use Model::bindModel()/Model::unbind() feature
so that you can dynamically alter the tables' association to minimize
table joins/queries.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Complex table relationship within one model

2007-09-05 Thread Mike Griffin

On 04/09/07, Jason <[EMAIL PROTECTED]> 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.

Hi!

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


Just set up the models as you would normally, but don't create
controllers or views for them.  This will make sure that no one can
edit or delete from your app as there will be no pages or functions to
do so.
You can reference the tables back from whatever controller you want by
using the $uses variable.

Try to just bake the application but leave out the controller and view
for each of these models, as you wont be using them.

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

In this case you can use the controller for each model, but don't
create the usual CRUD functions, only create what you need to access
the database with.

I hope this helped a bit.

Mike.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Complex table relationship within one model

2007-09-04 Thread Jason

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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---