Hello from a newbie to this group.

As far as I can see, CakePHP automagically ignores non-existent fields
when building a query. However, there is a problem when the query uses
more than one table.

Let me explain: In my project, a result list of Acts can be sorted by
a number of different fields from different models. To allow for
pagination, the model and field used for sorting are provided as a
named parameter in the URL:

http://localhost/cakephp/acts/index/page:1/sort:Model.field/direction:asc

Now I am thinking about someone toying around with the URL and
changing the sort param. As long as the field name is changed to some
name that does not exist in the current model, everything is fine:
CakePHP automagically ignores the field and returns the list, with
default sorting, without having performed an invalid query.

However, if the parameter is changed in such a way that the field name
represents a valid field name from the current model, problems occur
as soon as the model name is changed. Then, an invalid query is
performed and no result list returned.

Here's a simple example:

Model Act:
id
name
description

Model ActDate:
id
act_id
date

Act hasOne ActDate

http://localhost/cakephp/acts/index/page:1/sort:Act.name/direction:asc
http://localhost/cakephp/acts/index/page:1/sort:ActDate.date/direction:asc
=> both work as expected

http://localhost/cakephp/acts/index/page:1/sort:Act.xyz/direction:asc
http://localhost/cakephp/acts/index/page:1/sort:ActDate.xyz/direction:asc
=> both work as described above: sort parameter is ignored since field
"xyz" does not exist

http://localhost/cakephp/acts/index/page:1/sort:ActDate.name/direction:asc
http://localhost/cakephp/acts/index/page:1/sort:Xyz.description/direction:asc
=> both cause an invalid query, since "name" and "description" are
valid fields of model "Act", but ActDate.name and Xyz.description do
not exist


Before I create a custom-made function to make sure this does not
happen, I wonder if anyone might give me a hint to where to look in
the CakePHP core for the function that checks whether a field exists.
Perhaps it is easier to adjust this to my purposes than to do the
whole thing a second time.

Any hint would be greatly appreciated.

Thanks, baskerville

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