Re: Custom queries in cake PHP

2014-06-03 Thread Gavindra Kalikapersaud
*Nikhil, I was wondering where using the below code:*
* $output = $this->ModelName->query('SELECT Example FROM USER')*
*Isn't this vulnerable to sql injection? How to prevent this???*

On Sunday, August 12, 2012 2:01:47 AM UTC-4, Nikhil Agrawal wrote:
>
> Hey mohit,
>
> As a better practice never use queries in controller or view files. Always 
> use a model for all your db queries .
> Although you can use queries in both controller and models, i think it 
> can't be used in view files.
>
> *From controller:*
> $output = $this->ModelName->query('SELECT Example FROM USER')
> *From Model:*
> $output = $this->query('SELECT Example FROM USER')
>
> If any one has solution to use it in view file, pls share it.
> Thanks
>
> On Sun, Aug 12, 2012 at 10:23 AM, Yasir Arafat Hasib  > wrote:
>
>> Hello follow the url
>>
>> http://arafats.info/cakephp-custom-query/
>>
>> Is that ok for you?
>> Thanks
>>
>> On Mon, Aug 6, 2012 at 10:06 PM, mohit kumar > > wrote:
>>
>>> Hi Folks, 
>>> What is the best way to have custom queries from the databa se. I need 
>>> to query from one of the pages. 
>>>
>>>
>>> *With Best Regards, Mohit Kumar <http://kumarmohit.com>*
>>> *+91-9582894570*
>>>
>>>  -- 
>>> Our newest site for the community: CakePHP Video Tutorials 
>>> http://tv.cakephp.org 
>>> Check out the new CakePHP Questions site http://ask.cakephp.org and 
>>> help others with their CakePHP related questions.
>>>  
>>>  
>>> To unsubscribe from this group, send email to
>>> cake-php+u...@googlegroups.com  For more options, visit 
>>> this group at http://groups.google.com/group/cake-php
>>>
>>
>>
>>
>> -- 
>>
>>
>> *Thanks & 
>> Regards.-
>>  
>> Yasir Arafat (Hasib)*
>> *Deputy Project Manager, *Software Solutions
>> Grameen Solutions
>> Contact Information:
>>  Cell : +8801816 536 901, +880197 *333* 2 888
>> Web: http://arafats.info
>> <http://arafats.info>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To post to this group, send email to cake...@googlegroups.com 
>> .
>> To unsubscribe from this group, send email to 
>> cake-php+u...@googlegroups.com .
>> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>>  
>>  
>>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Custom queries in cake PHP

2012-08-11 Thread Nikhil Agrawal
Hey mohit,

As a better practice never use queries in controller or view files. Always
use a model for all your db queries .
Although you can use queries in both controller and models, i think it
can't be used in view files.

*From controller:*
$output = $this->ModelName->query('SELECT Example FROM USER')
*From Model:*
$output = $this->query('SELECT Example FROM USER')

If any one has solution to use it in view file, pls share it.
Thanks

On Sun, Aug 12, 2012 at 10:23 AM, Yasir Arafat Hasib wrote:

> Hello follow the url
>
> http://arafats.info/cakephp-custom-query/
>
> Is that ok for you?
> Thanks
>
> On Mon, Aug 6, 2012 at 10:06 PM, mohit kumar  wrote:
>
>> Hi Folks,
>> What is the best way to have custom queries from the databa se. I need to
>> query from one of the pages.
>>
>> *With Best Regards,
>> Mohit Kumar <http://kumarmohit.com>*
>> *+91-9582894570*
>>
>>  --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php
>>
>
>
>
> --
> *Thanks & Regards.
>
> -
> Yasir Arafat (Hasib)*
> *Deputy Project Manager, *Software Solutions
> Grameen Solutions
> Contact Information:
> **
> **
> Cell : +8801816 536 901, +880197 *333* 2 888
> Web: http://arafats.info
> <http://arafats.info>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Custom queries in cake PHP

2012-08-11 Thread Yasir Arafat Hasib
Hello follow the url

http://arafats.info/cakephp-custom-query/

Is that ok for you?
Thanks

On Mon, Aug 6, 2012 at 10:06 PM, mohit kumar  wrote:

> Hi Folks,
> What is the best way to have custom queries from the database. I need to
> query from one of the pages.
>
> *With Best Regards,
> Mohit Kumar <http://kumarmohit.com>*
> *+91-9582894570*
>
>  --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>



-- 
*Thanks & Regards.
-
Yasir Arafat (Hasib)*
*Deputy Project Manager, *Software Solutions
Grameen Solutions
Contact Information:
**
**
Cell : +8801816 536 901, +880197 *333* 2 888
Web: http://arafats.info
<http://arafats.info>

-- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Custom queries in cake PHP

2012-08-06 Thread lowpass
You don't. That should be in the model. From the view, you should look
into requestAction() to call a method in your controller. But before
you do that you should consider putting the logic in the controller to
begin with, and not in the view.

On Mon, Aug 6, 2012 at 1:29 PM, mohit kumar  wrote:
> How to use them in view template?
>
>
> With Best Regards,
> Mohit Kumar
> +91-9582894570
>
>
>
> On Mon, Aug 6, 2012 at 10:43 PM, Vinicius Dusso  wrote:
>>
>> Hi Mohit,
>>
>> You can use the 'query' method:
>>
>> $this->YourModel->query('SELECT * FROM table');
>>
>> Take a look in this tutorial:
>> http://book.cakephp.org/1.3/view/1027/query
>>
>> []'s
>>
>> Vinicius
>>
>> Em segunda-feira, 6 de agosto de 2012 13h06min53s UTC-3, mohit escreveu:
>>>
>>> Hi Folks,
>>> What is the best way to have custom queries from the database. I need to
>>> query from one of the pages.
>>>
>>> With Best Regards,
>>> Mohit Kumar
>>> +91-9582894570
>>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php
>
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom queries in cake PHP

2012-08-06 Thread mohit kumar
How to use them in view template?


*With Best Regards,
Mohit Kumar <http://kumarmohit.com>*
*+91-9582894570*



On Mon, Aug 6, 2012 at 10:43 PM, Vinicius Dusso  wrote:

> Hi Mohit,
>
> You can use the 'query' method:
>
> $this->YourModel->query('SELECT * FROM table');
>
> Take a look in this tutorial:
> http://book.cakephp.org/1.3/view/1027/query
>
> []'s
>
> Vinicius
>
> Em segunda-feira, 6 de agosto de 2012 13h06min53s UTC-3, mohit escreveu:
>
>> Hi Folks,
>> What is the best way to have custom queries from the database. I need to
>> query from one of the pages.
>>
>> *With Best Regards,
>> Mohit Kumar <http://kumarmohit.com>*
>> *+91-9582894570*
>>
>>  --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom queries in cake PHP

2012-08-06 Thread Vinicius Dusso
Hi Mohit,

You can use the 'query' method:

$this->YourModel->query('SELECT * FROM table');

Take a look in this tutorial:
http://book.cakephp.org/1.3/view/1027/query 

[]'s

Vinicius

Em segunda-feira, 6 de agosto de 2012 13h06min53s UTC-3, mohit escreveu:
>
> Hi Folks, 
> What is the best way to have custom queries from the database. I need to 
> query from one of the pages. 
>
> *With Best Regards,
> Mohit Kumar <http://kumarmohit.com>*
> *+91-9582894570*
>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Custom queries in cake PHP

2012-08-06 Thread mohit kumar
Hi Folks,
What is the best way to have custom queries from the database. I need to
query from one of the pages.

*With Best Regards,
Mohit Kumar <http://kumarmohit.com>*
*+91-9582894570*

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Custom queries test

2009-01-22 Thread Fabio Kreusch

I'm working with no prefixes..

On Jan 21, 10:04 pm, "websta*" 
wrote:
> If you get your database connection details from the ConnectionManager you
> will at least be able to deduce your table prefix and integrate this into
> your querries.
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
>
> Of Fabio Kreusch
> Sent: Thursday, January 22, 2009 10:48 AM
> To: CakePHP
> Subject: Custom queries test
>
> Hello all!
>
> I'm thinking about on how to test custom queries in a model.
>
> Suppose I have something like this in a model:
>
> function doSomethingWithCustomQuery() {
>   return $this->query('SELECT * FROM table');
> }
>
> How can I test this using the fixtures and all?
> My main problem is how to detect the test environment
> so I can, for exemple, attach 'test_suite' to the table name,
> so the query will run on the test table.
>
> How can I do this?
>
> Internal Virus Database is out of date.
> Checked by AVG -http://www.avg.com
> Version: 8.0.176 / Virus Database: 270.10.8/1899 - Release Date: 1/17/2009
> 5:50 PM
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



RE: Custom queries test

2009-01-21 Thread websta*

If you get your database connection details from the ConnectionManager you
will at least be able to deduce your table prefix and integrate this into
your querries.

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of Fabio Kreusch
Sent: Thursday, January 22, 2009 10:48 AM
To: CakePHP
Subject: Custom queries test


Hello all!

I'm thinking about on how to test custom queries in a model.

Suppose I have something like this in a model:

function doSomethingWithCustomQuery() {
  return $this->query('SELECT * FROM table');
}

How can I test this using the fixtures and all?
My main problem is how to detect the test environment
so I can, for exemple, attach 'test_suite' to the table name,
so the query will run on the test table.

How can I do this?


Internal Virus Database is out of date.
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.10.8/1899 - Release Date: 1/17/2009
5:50 PM


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Custom queries test

2009-01-21 Thread Fabio Kreusch

Hello all!

I'm thinking about on how to test custom queries in a model.

Suppose I have something like this in a model:

function doSomethingWithCustomQuery() {
  return $this->query('SELECT * FROM table');
}

How can I test this using the fixtures and all?
My main problem is how to detect the test environment
so I can, for exemple, attach 'test_suite' to the table name,
so the query will run on the test table.

How can I do this?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Custom queries/sql in models/behaviors

2008-12-06 Thread Adam Royle
d] => 3
> > >                         )
> > >                 )
> > >         )
> > > )
>
> > > On Dec 5, 4:08 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > > > Because I cant use foreign keys so all of those features are useless
> > > > to me. I also cant use linked models.
>
> > > > On Dec 5, 1:12 pm, teknoid <[EMAIL PROTECTED]> wrote:
>
> > > > > > I am not a big fan of the model system because its very limiting if 
> > > > > > you have advanced queries.
>
> > > > > How did you come to that conclusion?
>
> > > > > ...
>
> > > > > If you properly created your models and associations, a simple find
> > > > > ('all') will give you: Team, Roster, Game and League models with all
> > > > > the relevant info.
>
> > > > > On Dec 4, 6:23 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > > > > > Ok in my current system (its a gaming league) I have packages. I 
> > > > > > will
> > > > > > use a Team package as an example. In this Team package I have a 
> > > > > > method
> > > > > > getTeamInfo() which calls out to external queries. I do this so I 
> > > > > > only
> > > > > > have to write a query once and can access its results through a 
> > > > > > method
> > > > > > call. I prefer this way instead of having to write the same query 
> > > > > > over
> > > > > > and over for different instances.
>
> > > > > > require('teamExt.php');
> > > > > > require('userExt.php');
>
> > > > > > class Team {
>
> > > > > >         public static function getTeamInfo($team_id) {
> > > > > >                 $team = TeamExt::getTeamInfo($team_id);
>
> > > > > >                 if (!empty($team)) {
> > > > > >                         $team['roster'] = 
> > > > > > TeamExt::getRoster($team_id);
> > > > > >                         $team['games']  = 
> > > > > > TeamExt::getGamesPlayed($team_id);
> > > > > >                         $team['stats']  = 
> > > > > > TeamExt::getStats($team_id);
> > > > > >                         $team['leader'] = 
> > > > > > UserExt::getUser($team['leader_id']);
> > > > > >                 }
>
> > > > > >                 return $team;
> > > > > >         }
>
> > > > > > }
>
> > > > > > Now when I call Team::getTeamInfo I should have its team info, 
> > > > > > roster,
> > > > > > games played, the team leader and league statistics. Now the problem
> > > > > > with CakePHP is its model system. I am not a big fan of the model
> > > > > > system because its very limiting if you have advanced queries. I was
> > > > > > thinking of doing it this way:
>
> > > > > > Class Team = Model Team
> > > > > > TeamExt = Team Behavior
> > > > > > UserExt = User Behavior
>
> > > > > > $team = $this->Team->getTeamInfo();
>
> > > > > > But how would I do custom queries in a behavior? And the logic for
> > > > > > behavior is wrong with my idea anyways. Anyone have an idea of how I
> > > > > > can accomplish my setup in CakePHP, because this is the one thing
> > > > > > stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Custom queries/sql in models/behaviors

2008-12-06 Thread gearvOsh
ome to that conclusion?
>
> > > > ...
>
> > > > If you properly created your models and associations, a simple find
> > > > ('all') will give you: Team, Roster, Game and League models with all
> > > > the relevant info.
>
> > > > On Dec 4, 6:23 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > > > > Ok in my current system (its a gaming league) I have packages. I will
> > > > > use a Team package as an example. In this Team package I have a method
> > > > > getTeamInfo() which calls out to external queries. I do this so I only
> > > > > have to write a query once and can access its results through a method
> > > > > call. I prefer this way instead of having to write the same query over
> > > > > and over for different instances.
>
> > > > > require('teamExt.php');
> > > > > require('userExt.php');
>
> > > > > class Team {
>
> > > > >         public static function getTeamInfo($team_id) {
> > > > >                 $team = TeamExt::getTeamInfo($team_id);
>
> > > > >                 if (!empty($team)) {
> > > > >                         $team['roster'] = 
> > > > > TeamExt::getRoster($team_id);
> > > > >                         $team['games']  = 
> > > > > TeamExt::getGamesPlayed($team_id);
> > > > >                         $team['stats']  = TeamExt::getStats($team_id);
> > > > >                         $team['leader'] = 
> > > > > UserExt::getUser($team['leader_id']);
> > > > >                 }
>
> > > > >                 return $team;
> > > > >         }
>
> > > > > }
>
> > > > > Now when I call Team::getTeamInfo I should have its team info, roster,
> > > > > games played, the team leader and league statistics. Now the problem
> > > > > with CakePHP is its model system. I am not a big fan of the model
> > > > > system because its very limiting if you have advanced queries. I was
> > > > > thinking of doing it this way:
>
> > > > > Class Team = Model Team
> > > > > TeamExt = Team Behavior
> > > > > UserExt = User Behavior
>
> > > > > $team = $this->Team->getTeamInfo();
>
> > > > > But how would I do custom queries in a behavior? And the logic for
> > > > > behavior is wrong with my idea anyways. Anyone have an idea of how I
> > > > > can accomplish my setup in CakePHP, because this is the one thing
> > > > > stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Custom queries/sql in models/behaviors

2008-12-06 Thread Adam Royle

Add:

var $actsAs = array('Containable');

to your Team model.

Then add this before your find() call:

$this->Team->contain('TeamMember' => array('User'), 'TeamGame');

Cheers,
Adam

On Dec 6, 12:51 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
> Ok thats weird, I dont have foreign keys really setup but it still
> works. Im using $hasMany for members and games. But within the
> TeamMember and TeamGame arrays, is there way to get more information
> returned? I would need the members name, avatar, etc.
>
> Array
> (
>     [0] => Array
>         (
>             [Team] => Array
>                 (
>                     [id] => 1
>                     [status] => approved
>                     [name] => chair
>                     [tag] => _h_
>                     [urlName] =>
>                     [website] =>
>                     [irc] =>
>                     [about] =>
>                     [servers] =>
>                     [logo] =>
>                     [createDate] => 0
>                     [state_id] => 0
>                     [country_id] => 0
>                     [created] =>
>                     [modified] =>
>                 )
>
>             [TeamMember] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 4
>                             [team_id] => 1
>                             [user_id] => 32
>                             [role] => captain
>                             [status] => approved
>                             [joinDate] => 1211498560
>                         )
>                 )
>
>             [TeamGame] => Array
>                 (
>                     [0] => Array
>                         (
>                             [team_id] => 1
>                             [gameSystem_id] => 3
>                         )
>                 )
>         )
> )
>
> On Dec 5, 4:08 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > Because I cant use foreign keys so all of those features are useless
> > to me. I also cant use linked models.
>
> > On Dec 5, 1:12 pm, teknoid <[EMAIL PROTECTED]> wrote:
>
> > > > I am not a big fan of the model system because its very limiting if you 
> > > > have advanced queries.
>
> > > How did you come to that conclusion?
>
> > > ...
>
> > > If you properly created your models and associations, a simple find
> > > ('all') will give you: Team, Roster, Game and League models with all
> > > the relevant info.
>
> > > On Dec 4, 6:23 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > > > Ok in my current system (its a gaming league) I have packages. I will
> > > > use a Team package as an example. In this Team package I have a method
> > > > getTeamInfo() which calls out to external queries. I do this so I only
> > > > have to write a query once and can access its results through a method
> > > > call. I prefer this way instead of having to write the same query over
> > > > and over for different instances.
>
> > > > require('teamExt.php');
> > > > require('userExt.php');
>
> > > > class Team {
>
> > > >         public static function getTeamInfo($team_id) {
> > > >                 $team = TeamExt::getTeamInfo($team_id);
>
> > > >                 if (!empty($team)) {
> > > >                         $team['roster'] = TeamExt::getRoster($team_id);
> > > >                         $team['games']  = 
> > > > TeamExt::getGamesPlayed($team_id);
> > > >                         $team['stats']  = TeamExt::getStats($team_id);
> > > >                         $team['leader'] = 
> > > > UserExt::getUser($team['leader_id']);
> > > >                 }
>
> > > >                 return $team;
> > > >         }
>
> > > > }
>
> > > > Now when I call Team::getTeamInfo I should have its team info, roster,
> > > > games played, the team leader and league statistics. Now the problem
> > > > with CakePHP is its model system. I am not a big fan of the model
> > > > system because its very limiting if you have advanced queries. I was
> > > > thinking of doing it this way:
>
> > > > Class Team = Model Team
> > > > TeamExt = Team Behavior
> > > > UserExt = User Behavior
>
> > > > $team = $this->Team->getTeamInfo();
>
> > > > But how would I do custom queries in a behavior? And the logic for
> > > > behavior is wrong with my idea anyways. Anyone have an idea of how I
> > > > can accomplish my setup in CakePHP, because this is the one thing
> > > > stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Custom queries/sql in models/behaviors

2008-12-05 Thread gearvOsh

Ok thats weird, I dont have foreign keys really setup but it still
works. Im using $hasMany for members and games. But within the
TeamMember and TeamGame arrays, is there way to get more information
returned? I would need the members name, avatar, etc.

Array
(
[0] => Array
(
[Team] => Array
(
[id] => 1
[status] => approved
[name] => chair
[tag] => _h_
[urlName] =>
[website] =>
[irc] =>
[about] =>
[servers] =>
[logo] =>
[createDate] => 0
[state_id] => 0
[country_id] => 0
[created] =>
[modified] =>
)

[TeamMember] => Array
(
[0] => Array
(
[id] => 4
[team_id] => 1
[user_id] => 32
[role] => captain
[status] => approved
[joinDate] => 1211498560
)
)

[TeamGame] => Array
(
[0] => Array
(
[team_id] => 1
[gameSystem_id] => 3
)
)
)
)



On Dec 5, 4:08 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
> Because I cant use foreign keys so all of those features are useless
> to me. I also cant use linked models.
>
> On Dec 5, 1:12 pm, teknoid <[EMAIL PROTECTED]> wrote:
>
> > > I am not a big fan of the model system because its very limiting if you 
> > > have advanced queries.
>
> > How did you come to that conclusion?
>
> > ...
>
> > If you properly created your models and associations, a simple find
> > ('all') will give you: Team, Roster, Game and League models with all
> > the relevant info.
>
> > On Dec 4, 6:23 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > > Ok in my current system (its a gaming league) I have packages. I will
> > > use a Team package as an example. In this Team package I have a method
> > > getTeamInfo() which calls out to external queries. I do this so I only
> > > have to write a query once and can access its results through a method
> > > call. I prefer this way instead of having to write the same query over
> > > and over for different instances.
>
> > > require('teamExt.php');
> > > require('userExt.php');
>
> > > class Team {
>
> > >         public static function getTeamInfo($team_id) {
> > >                 $team = TeamExt::getTeamInfo($team_id);
>
> > >                 if (!empty($team)) {
> > >                         $team['roster'] = TeamExt::getRoster($team_id);
> > >                         $team['games']  = 
> > > TeamExt::getGamesPlayed($team_id);
> > >                         $team['stats']  = TeamExt::getStats($team_id);
> > >                         $team['leader'] = 
> > > UserExt::getUser($team['leader_id']);
> > >                 }
>
> > >                 return $team;
> > >         }
>
> > > }
>
> > > Now when I call Team::getTeamInfo I should have its team info, roster,
> > > games played, the team leader and league statistics. Now the problem
> > > with CakePHP is its model system. I am not a big fan of the model
> > > system because its very limiting if you have advanced queries. I was
> > > thinking of doing it this way:
>
> > > Class Team = Model Team
> > > TeamExt = Team Behavior
> > > UserExt = User Behavior
>
> > > $team = $this->Team->getTeamInfo();
>
> > > But how would I do custom queries in a behavior? And the logic for
> > > behavior is wrong with my idea anyways. Anyone have an idea of how I
> > > can accomplish my setup in CakePHP, because this is the one thing
> > > stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Custom queries/sql in models/behaviors

2008-12-05 Thread gearvOsh

Because I cant use foreign keys so all of those features are useless
to me. I also cant use linked models.


On Dec 5, 1:12 pm, teknoid <[EMAIL PROTECTED]> wrote:
> > I am not a big fan of the model system because its very limiting if you 
> > have advanced queries.
>
> How did you come to that conclusion?
>
> ...
>
> If you properly created your models and associations, a simple find
> ('all') will give you: Team, Roster, Game and League models with all
> the relevant info.
>
> On Dec 4, 6:23 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
>
> > Ok in my current system (its a gaming league) I have packages. I will
> > use a Team package as an example. In this Team package I have a method
> > getTeamInfo() which calls out to external queries. I do this so I only
> > have to write a query once and can access its results through a method
> > call. I prefer this way instead of having to write the same query over
> > and over for different instances.
>
> > require('teamExt.php');
> > require('userExt.php');
>
> > class Team {
>
> >         public static function getTeamInfo($team_id) {
> >                 $team = TeamExt::getTeamInfo($team_id);
>
> >                 if (!empty($team)) {
> >                         $team['roster'] = TeamExt::getRoster($team_id);
> >                         $team['games']  = TeamExt::getGamesPlayed($team_id);
> >                         $team['stats']  = TeamExt::getStats($team_id);
> >                         $team['leader'] = 
> > UserExt::getUser($team['leader_id']);
> >                 }
>
> >                 return $team;
> >         }
>
> > }
>
> > Now when I call Team::getTeamInfo I should have its team info, roster,
> > games played, the team leader and league statistics. Now the problem
> > with CakePHP is its model system. I am not a big fan of the model
> > system because its very limiting if you have advanced queries. I was
> > thinking of doing it this way:
>
> > Class Team = Model Team
> > TeamExt = Team Behavior
> > UserExt = User Behavior
>
> > $team = $this->Team->getTeamInfo();
>
> > But how would I do custom queries in a behavior? And the logic for
> > behavior is wrong with my idea anyways. Anyone have an idea of how I
> > can accomplish my setup in CakePHP, because this is the one thing
> > stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Custom queries/sql in models/behaviors

2008-12-05 Thread teknoid

> I am not a big fan of the model system because its very limiting if you have 
> advanced queries.

How did you come to that conclusion?

...

If you properly created your models and associations, a simple find
('all') will give you: Team, Roster, Game and League models with all
the relevant info.


On Dec 4, 6:23 pm, gearvOsh <[EMAIL PROTECTED]> wrote:
> Ok in my current system (its a gaming league) I have packages. I will
> use a Team package as an example. In this Team package I have a method
> getTeamInfo() which calls out to external queries. I do this so I only
> have to write a query once and can access its results through a method
> call. I prefer this way instead of having to write the same query over
> and over for different instances.
>
> require('teamExt.php');
> require('userExt.php');
>
> class Team {
>
>         public static function getTeamInfo($team_id) {
>                 $team = TeamExt::getTeamInfo($team_id);
>
>                 if (!empty($team)) {
>                         $team['roster'] = TeamExt::getRoster($team_id);
>                         $team['games']  = TeamExt::getGamesPlayed($team_id);
>                         $team['stats']  = TeamExt::getStats($team_id);
>                         $team['leader'] = 
> UserExt::getUser($team['leader_id']);
>                 }
>
>                 return $team;
>         }
>
> }
>
> Now when I call Team::getTeamInfo I should have its team info, roster,
> games played, the team leader and league statistics. Now the problem
> with CakePHP is its model system. I am not a big fan of the model
> system because its very limiting if you have advanced queries. I was
> thinking of doing it this way:
>
> Class Team = Model Team
> TeamExt = Team Behavior
> UserExt = User Behavior
>
> $team = $this->Team->getTeamInfo();
>
> But how would I do custom queries in a behavior? And the logic for
> behavior is wrong with my idea anyways. Anyone have an idea of how I
> can accomplish my setup in CakePHP, because this is the one thing
> stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Custom queries/sql in models/behaviors

2008-12-05 Thread Adam Royle

First of all, welcome to cakephp!

Cake's Model layer can be a big timesaver, so I suggest you get to
know it a bit better before dismissing it. However, you can execute
custom queries by using the $model->query() method. The one anomaly
with this is that cake transforms the results into a cake-like
structure. It can be good or bad depending on what you need to do, but
keep in mind you may need to massage the results a bit.

Behaviors are meant to be generic and reusable, so unless you have
more than one Team model, I would just add your methods into your Team
Model rather than create a behavior for it.

Instead of repeating your $model->query() or $model->find() calls
throughout your controller, you can just add that code into a method
in your team model.

function getStuff($id) {
return $this-find('all', array('conditions' => 'blah'));
}

Hope that helps.

Cheers,
Adam

On Dec 5, 9:23 am, gearvOsh <[EMAIL PROTECTED]> wrote:
> Ok in my current system (its a gaming league) I have packages. I will
> use a Team package as an example. In this Team package I have a method
> getTeamInfo() which calls out to external queries. I do this so I only
> have to write a query once and can access its results through a method
> call. I prefer this way instead of having to write the same query over
> and over for different instances.
>
> require('teamExt.php');
> require('userExt.php');
>
> class Team {
>
>         public static function getTeamInfo($team_id) {
>                 $team = TeamExt::getTeamInfo($team_id);
>
>                 if (!empty($team)) {
>                         $team['roster'] = TeamExt::getRoster($team_id);
>                         $team['games']  = TeamExt::getGamesPlayed($team_id);
>                         $team['stats']  = TeamExt::getStats($team_id);
>                         $team['leader'] = 
> UserExt::getUser($team['leader_id']);
>                 }
>
>                 return $team;
>         }
>
> }
>
> Now when I call Team::getTeamInfo I should have its team info, roster,
> games played, the team leader and league statistics. Now the problem
> with CakePHP is its model system. I am not a big fan of the model
> system because its very limiting if you have advanced queries. I was
> thinking of doing it this way:
>
> Class Team = Model Team
> TeamExt = Team Behavior
> UserExt = User Behavior
>
> $team = $this->Team->getTeamInfo();
>
> But how would I do custom queries in a behavior? And the logic for
> behavior is wrong with my idea anyways. Anyone have an idea of how I
> can accomplish my setup in CakePHP, because this is the one thing
> stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~--~~~~--~~--~--~---



Custom queries/sql in models/behaviors

2008-12-04 Thread gearvOsh

Ok in my current system (its a gaming league) I have packages. I will
use a Team package as an example. In this Team package I have a method
getTeamInfo() which calls out to external queries. I do this so I only
have to write a query once and can access its results through a method
call. I prefer this way instead of having to write the same query over
and over for different instances.

require('teamExt.php');
require('userExt.php');

class Team {

public static function getTeamInfo($team_id) {
$team = TeamExt::getTeamInfo($team_id);

if (!empty($team)) {
$team['roster'] = TeamExt::getRoster($team_id);
$team['games']  = TeamExt::getGamesPlayed($team_id);
$team['stats']  = TeamExt::getStats($team_id);
$team['leader'] = UserExt::getUser($team['leader_id']);
}

return $team;
}
}

Now when I call Team::getTeamInfo I should have its team info, roster,
games played, the team leader and league statistics. Now the problem
with CakePHP is its model system. I am not a big fan of the model
system because its very limiting if you have advanced queries. I was
thinking of doing it this way:

Class Team = Model Team
TeamExt = Team Behavior
UserExt = User Behavior

$team = $this->Team->getTeamInfo();

But how would I do custom queries in a behavior? And the logic for
behavior is wrong with my idea anyways. Anyone have an idea of how I
can accomplish my setup in CakePHP, because this is the one thing
stopping me from using CakePHP. And no I will not use joins.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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: Paginating results of custom queries?

2007-08-02 Thread kabturek

by default paginator in 1.2 is doing a findAll with the conditions
that you give him but if that's not enough for you then you can
declare a paginate function in your model that will be used instead of
findAll  ( 
http://api.cakephp.org/1.2/libs_2controller_2controller_8php-source.html#l01100
)  you should also define a paginateCount() function in your model.
You've got the params in the API. I suggest using it :) it's a
powerfull tool.

greets,

On Aug 1, 5:19 pm, kionae <[EMAIL PROTECTED]> wrote:
> No one knows?
>
> On Jul 30, 3:48 pm, kionae <[EMAIL PROTECTED]> wrote:
>
> > Is there any way to just pass an array into 1.2's paginate function
> > and have it paginate the data?  Essentially, I have an array that is a
> > set of search results returned by some custom queries and a bit of
> > manipulation.  I couldn't generate the results I needed by going
> > through $this->paginate because it wouldn't let me join tables, so I'm
> > stuck with using the custom queries.
>
> > I've seen other topics on this, but there didn't seem to be a clear
> > answer (in fact I'm still not even sure this is possible after reading
> > them all).


--~--~-~--~~~---~--~~
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: Paginating results of custom queries?

2007-08-01 Thread Arjen V
I've done this a while back. It probably isn't the best way, but it works.
I'm not sure if this was done with the most recent alpha, but it's easy to
recreate: just remove the code that's used to run the findAll query and make
it use the one you supply.

cake/app_controller.php

  function paginateResultSet($object = null, $results)
  {

  if (is_array($object)) {
  $whitelist = $scope;
  $scope = $object;
  $object = null;
  }

  if (is_string($object)) {
  if (isset($this->{$object})) {
  $object = $this->{$object};
  } elseif (isset($this->{$this->modelClass}) &&
isset($this->{$this->modelClass}->{$object})) {
  $object = $this->{$this->modelClass}->{$object};
  } elseif (!empty($this->uses)) {
  for ($i = 0; $i < count($this->uses); $i++) {
  $model = $this->uses[$i];
  if (isset($this->{$model}->{$object})) {
  $object = $this->{$model}->{$object};
  break;
  }
  }
  }
  } elseif (empty($object) || $object == null) {
  if (isset($this->{$this->modelClass})) {
  $object = $this->{$this->modelClass};
  } else {
  $object = $this->{$this->uses[0]};
  }
  }

  if (!is_object($object)) {
  // Error: can't find object
  return array();
  }
  $options = am($this->params, $this->params['url'], $this->passedArgs);

  if (isset($this->paginate[$object->name])) {
  $defaults = $this->paginate[$object->name];
  } else {
  $defaults = $this->paginate;
  }

  if (isset($options['show'])) {
  $options['limit'] = $options['show'];
  }

  if (isset($options['sort']) && isset($options['direction'])) {
  $options['order'] = array($options['sort'] =>
$options['direction']);
  } elseif (isset($options['sort'])) {
  $options['order'] = array($options['sort'] => 'asc');
  }

  if (!empty($options['order']) && is_array($options['order'])) {
  $key = key($options['order']);
  if (strpos($key, '.') === false && $object->hasField($key)) {
  $options['order'][$object->name . '.' . $key] =
$options['order'][$key];
  unset($options['order'][$key]);
  }
  }

  $vars = array('fields', 'order', 'limit', 'page', 'recursive');
  $keys = array_keys($options);
  $count = count($keys);

  for($i = 0; $i < $count; $i++) {
  if (!in_array($keys[$i], $vars)) {
  unset($options[$keys[$i]]);
  }
  if (empty($whitelist) && ($keys[$i] == 'fields' || $keys[$i] ==
'recursive')) {
  unset($options[$keys[$i]]);
  } elseif (!empty($whitelist) && !in_array($keys[$i], $whitelist))
{
  unset($options[$keys[$i]]);
  }
  }

  $conditions = $fields = $order = $limit = $page = $recursive = null;
  if (!isset($defaults['conditions'])) {
  $defaults['conditions'] = array();
  }

  extract($options = am(array('page' => 1, 'limit' => 20), $defaults,
$options));
  /*if (is_array($scope) && !empty($scope)) {
  $conditions = am($conditions, $scope);
  } elseif (is_string($scope)) {
  $conditions = array($conditions, $scope);
  }
  $recursive = $object->recursive;
  */
  $count = $object->findCount($conditions, $recursive);
  $pageCount = ceil($count / $limit);

  if($page == 'last') {
  $options['page'] = $page = $pageCount;
  }

  //$results = $object->findAll($conditions, $fields, $order, $limit,
$page, $recursive);
  $paging = array(
  'page'=> $page,
  'current'=> count($results),
  'count'=> $count,
  'prevPage'=> ($page > 1),
  'nextPage'=> ($count > ($page * $limit)),
  'pageCount'=> $pageCount,
  'defaults'=> am(array('limit' => 20, 'step' => 1), $defaults),

  'options'=> $options
  );

  $this->params['paging'][$object->name] = $paging;

  if (!in_array('Paginator', $this->helpers) &&
!ar

Re: Paginating results of custom queries?

2007-08-01 Thread Ketan Patel

You will have to overload the paginate method in your model. And then
in the model you could write your custom queries as required. Read the
code for more information.

Ketan.

kionae wrote:
> Is there any way to just pass an array into 1.2's paginate function
> and have it paginate the data?  Essentially, I have an array that is a
> set of search results returned by some custom queries and a bit of
> manipulation.  I couldn't generate the results I needed by going
> through $this->paginate because it wouldn't let me join tables, so I'm
> stuck with using the custom queries.
>
> I've seen other topics on this, but there didn't seem to be a clear
> answer (in fact I'm still not even sure this is possible after reading
> them all).


--~--~-~--~~~---~--~~
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: Paginating results of custom queries?

2007-08-01 Thread rtconner

Just found this link, give it a read also, maybe it can help you.
http://groups.google.com/group/cake-php/browse_frm/thread/8cbf01f7a9acda57/9e84f7aacbf3cd85?#9e84f7aacbf3cd85

On Aug 1, 9:32 am, rtconner <[EMAIL PROTECTED]> wrote:
> Yeah I'm doubting anyone has a good answer for you.
>
> "Is there any way to just pass an array into 1.2's paginate function
> and have it paginate the data?"
>
> No. Sorry.
>
> If you work hard enough, likely I'm thinking you can join the tables
> you want to join. I came across this once, and I kind of ended up
> writing a "fake_paginate" method to do it. Not a great idea. Another
> thing, I've never tried, but have been meaning to try is this: In your
> relationship definitions in your models.. I'm theorizing you can write
> some combination of finderQuery and counterQuery and then paginate
> will use them and happily work. These are area I've never really
> explored so really I have no idea if they'll work. It's just a theory
> I have.
>
> -Rob Conner
>
> On Aug 1, 9:19 am, kionae <[EMAIL PROTECTED]> wrote:
>
> > No one knows?
>
> > On Jul 30, 3:48 pm, kionae <[EMAIL PROTECTED]> wrote:
>
> > > Is there any way to just pass an array into 1.2's paginate function
> > > and have it paginate the data?  Essentially, I have an array that is a
> > > set of search results returned by some custom queries and a bit of
> > > manipulation.  I couldn't generate the results I needed by going
> > > through $this->paginate because it wouldn't let me join tables, so I'm
> > > stuck with using the custom queries.
>
> > > I've seen other topics on this, but there didn't seem to be a clear
> > > answer (in fact I'm still not even sure this is possible after reading
> > > them all).


--~--~-~--~~~---~--~~
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: Paginating results of custom queries?

2007-08-01 Thread rtconner

Yeah I'm doubting anyone has a good answer for you.

"Is there any way to just pass an array into 1.2's paginate function
and have it paginate the data?"

No. Sorry.

If you work hard enough, likely I'm thinking you can join the tables
you want to join. I came across this once, and I kind of ended up
writing a "fake_paginate" method to do it. Not a great idea. Another
thing, I've never tried, but have been meaning to try is this: In your
relationship definitions in your models.. I'm theorizing you can write
some combination of finderQuery and counterQuery and then paginate
will use them and happily work. These are area I've never really
explored so really I have no idea if they'll work. It's just a theory
I have.

-Rob Conner

On Aug 1, 9:19 am, kionae <[EMAIL PROTECTED]> wrote:
> No one knows?
>
> On Jul 30, 3:48 pm, kionae <[EMAIL PROTECTED]> wrote:
>
> > Is there any way to just pass an array into 1.2's paginate function
> > and have it paginate the data?  Essentially, I have an array that is a
> > set of search results returned by some custom queries and a bit of
> > manipulation.  I couldn't generate the results I needed by going
> > through $this->paginate because it wouldn't let me join tables, so I'm
> > stuck with using the custom queries.
>
> > I've seen other topics on this, but there didn't seem to be a clear
> > answer (in fact I'm still not even sure this is possible after reading
> > them all).


--~--~-~--~~~---~--~~
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: Paginating results of custom queries?

2007-08-01 Thread kionae

No one knows?

On Jul 30, 3:48 pm, kionae <[EMAIL PROTECTED]> wrote:
> Is there any way to just pass an array into 1.2's paginate function
> and have it paginate the data?  Essentially, I have an array that is a
> set of search results returned by some custom queries and a bit of
> manipulation.  I couldn't generate the results I needed by going
> through $this->paginate because it wouldn't let me join tables, so I'm
> stuck with using the custom queries.
>
> I've seen other topics on this, but there didn't seem to be a clear
> answer (in fact I'm still not even sure this is possible after reading
> them all).


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



Paginating results of custom queries?

2007-07-30 Thread kionae

Is there any way to just pass an array into 1.2's paginate function
and have it paginate the data?  Essentially, I have an array that is a
set of search results returned by some custom queries and a bit of
manipulation.  I couldn't generate the results I needed by going
through $this->paginate because it wouldn't let me join tables, so I'm
stuck with using the custom queries.

I've seen other topics on this, but there didn't seem to be a clear
answer (in fact I'm still not even sure this is possible after reading
them all).


--~--~-~--~~~---~--~~
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: Regarding custom queries

2007-07-10 Thread AD7six



On Jul 10, 9:56 am, mussond <[EMAIL PROTECTED]> wrote:
> Why is $this->query() to be avoided?  I'm trying to use it but I'm
> having trouble getting the values it produces from the array.

Because it's the easiest way to introduce insecure queries into your
application?
Because a change to use a different db then means rewriting your
application model code?
Because you cannot take advantage of most of cakes model features by
doing so?
Because it's a lot harder to read?
Because why write sql when you don' t need to?
Because it makes you life a lot easier to use the methods cunningly
hidden in plain sight throughout all tutorials, the source code, the
manual and the api?

Take your pick,

AD
PS look in the api at the method Model::findCount


--~--~-~--~~~---~--~~
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: Regarding custom queries

2007-07-10 Thread mussond

Why is $this->query() to be avoided?  I'm trying to use it but I'm
having trouble getting the values it produces from the array.

Is theres a better way for me to query tables?

oh, what I' trying to do is count the number of rows in a table bassed
on a project ID, that I get from a user ID.

On Jul 9, 11:49 pm, Geoff Ford <[EMAIL PROTECTED]> wrote:
> To clarify AD a bit
>
> Where you have:
> $this->query("UPDATE customers SET password='$pass' WHERE
> id='$id'");
>
> You should have:
> $this->id = $id;
> $this->saveField('password', $pass);
>
> You should try to avoid using $this->query() unless you really have
> to.
>
> To query the inventory table you need an Inventory model.  THen in
> your controller you can do:
> $this->Customer->changepass($id, $pass);
> $this->Inventory->findAll(array('customer_id' => $id));
>
> Or whatever it is you need to do.  Models should be independent, so
> one model should not query anothers table.  It should be done in the
> controller.
>
> I think you need to go back and read the manual a bit more.  This is
> all explained quite well.
>
> Geoff
> --http://lemoncake.wordpress.com
>
> On Jul 10, 2:12 pm, reeta <[EMAIL PROTECTED]> wrote:
>
> > Hi AD ! thanks for the help but i want to know if i want to run query
> > on another model then how could i do this?suppose i want to run
> > query() from inventory table in customer model class ,then how could i
> > do this?and another question is i m not getting value for last insert
> > id.There is a function named as getLastInsertId(),but it is not giving
> > result.
>
> > On Jul 9, 2:37 pm, AD7six <[EMAIL PROTECTED]> wrote:
>
> > > On Jul 9, 11:06 am, reeta <[EMAIL PROTECTED]> wrote:
> > > 
>
> > > > now in model class:-
> > > > function changepass($pass,$id)
> > > > {
> > > >  $this->query("UPDATE customers SET password='$pass' WHERE
> > > > id='$id'");
>
> > > Why are you using query instead of save or saveField..?
> > > If you don't want to use the features of the framework, why use the
> > > framework?
>
> > > > This is working well,but if i want to run query on another table then
> > > > how can i do this?
>
> > > You call save (or whatever) on the other model.
>
> > > 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: Regarding custom queries

2007-07-09 Thread Geoff Ford

To clarify AD a bit

Where you have:
$this->query("UPDATE customers SET password='$pass' WHERE
id='$id'");

You should have:
$this->id = $id;
$this->saveField('password', $pass);

You should try to avoid using $this->query() unless you really have
to.

To query the inventory table you need an Inventory model.  THen in
your controller you can do:
$this->Customer->changepass($id, $pass);
$this->Inventory->findAll(array('customer_id' => $id));

Or whatever it is you need to do.  Models should be independent, so
one model should not query anothers table.  It should be done in the
controller.

I think you need to go back and read the manual a bit more.  This is
all explained quite well.

Geoff
--
http://lemoncake.wordpress.com


On Jul 10, 2:12 pm, reeta <[EMAIL PROTECTED]> wrote:
> Hi AD ! thanks for the help but i want to know if i want to run query
> on another model then how could i do this?suppose i want to run
> query() from inventory table in customer model class ,then how could i
> do this?and another question is i m not getting value for last insert
> id.There is a function named as getLastInsertId(),but it is not giving
> result.
>
> On Jul 9, 2:37 pm, AD7six <[EMAIL PROTECTED]> wrote:
>
> > On Jul 9, 11:06 am, reeta <[EMAIL PROTECTED]> wrote:
> > 
>
> > > now in model class:-
> > > function changepass($pass,$id)
> > > {
> > >  $this->query("UPDATE customers SET password='$pass' WHERE
> > > id='$id'");
>
> > Why are you using query instead of save or saveField..?
> > If you don't want to use the features of the framework, why use the
> > framework?
>
> > > This is working well,but if i want to run query on another table then
> > > how can i do this?
>
> > You call save (or whatever) on the other model.
>
> > 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: Regarding custom queries

2007-07-09 Thread reeta

Hi AD ! thanks for the help but i want to know if i want to run query
on another model then how could i do this?suppose i want to run
query() from inventory table in customer model class ,then how could i
do this?and another question is i m not getting value for last insert
id.There is a function named as getLastInsertId(),but it is not giving
result.

On Jul 9, 2:37 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Jul 9, 11:06 am, reeta <[EMAIL PROTECTED]> wrote:
> 
>
> > now in model class:-
> > function changepass($pass,$id)
> > {
> >  $this->query("UPDATE customers SET password='$pass' WHERE
> > id='$id'");
>
> Why are you using query instead of save or saveField..?
> If you don't want to use the features of the framework, why use the
> framework?
>
> > This is working well,but if i want to run query on another table then
> > how can i do this?
>
> You call save (or whatever) on the other model.
>
> 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: Regarding custom queries

2007-07-09 Thread AD7six



On Jul 9, 11:06 am, reeta <[EMAIL PROTECTED]> wrote:

> now in model class:-
> function changepass($pass,$id)
> {
>  $this->query("UPDATE customers SET password='$pass' WHERE
> id='$id'");

Why are you using query instead of save or saveField..?
If you don't want to use the features of the framework, why use the
framework?


> This is working well,but if i want to run query on another table then
> how can i do this?

You call save (or whatever) on the other model.

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



Regarding custom queries

2007-07-09 Thread reeta

Hi everybody.I have a question ,if anybody know then please solve my
query.
I have a model class named 'Customer' and controller class of it
'Customers_controller'.
earlier i was using query() in my controller class but after reading a
post now i m using it in my model class like --

In controller class:-
$this->Customer->changepass($pass,$id);
where $pass is password and $id is id.

now in model class:-
function changepass($pass,$id)
{
 $this->query("UPDATE customers SET password='$pass' WHERE
id='$id'");
return;
}

This is working well,but if i want to run query on another table then
how can i do this?
Suppose i want to run update query on inventory table in customer
model , then how will i do this in model class?is there any other
changes will occur except query() ?

Sorry for my English because my English is not so good.


--~--~-~--~~~---~--~~
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: custom queries and mysql_fetch_field

2006-11-18 Thread jonathan.snook

On Nov 18, 5:51 pm, "nate" <[EMAIL PROTECTED]> wrote:
> I had this happen once.  I believe it has something to do with how your
> database encoding is set up.

Upon further inspection, I believe it occurs when MySQL has to create a
temporary table during the SELECT process. This is more likely to occur
in a GROUP BY or ORDER BY (according to the docs). The question is
whether you could reliable identify a temporary table. It seems to have
a consistent naming convention (#sql_XXX_0). Not sure how much you'd
want to rely on that.

Alternatively, you could do one of two things:

1. check all configured models in the app and if the table name isn't
one of them, give it a consistent name (I believe it's '0' currently
but maybe something like '_unknown' would be more accurate).
2. do a 'show tables' on the database and compare against that. If it's
not in the list, it's temporary. You could cache this info like you
would a 'DESC tablename'.

Anyways, those are my thoughts.


--~--~-~--~~~---~--~~
 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: custom queries and mysql_fetch_field

2006-11-18 Thread nate

I had this happen once.  I believe it has something to do with how your
database encoding is set up.


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



custom queries and mysql_fetch_field

2006-11-18 Thread jonathan.snook

So, I've been trying to track down a solution to this problem and I
haven't found it yet. (I should probably open a trac ticket but figured
I'd shoot out the question here first).

Okay, I have a custom query doing some fun stuff, but anytime I'm using
mysql functions (like COUNT or SUBSTRING or whatever) I alias the name
to something meaningful like 'fieldcount'.  The problem is the array I
get back:

Array
(
[Item] => Array
(
[name] => asdfas
)
[#sql_13b_0] => Array
(
[mydate] => 1983-03-21 21:00:00
)
)

As you can see, the #sql_13b_0 part isn't what I want. In trying to
trace things back through the code, I'm noticing that it may in fact be
MySQL returning this value during a mysql_fetch_field call.

Question is... can I specify something more meaningful or have it at
least default to something consistent?


--~--~-~--~~~---~--~~
 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: Pagination using multiple models and custom queries

2006-09-08 Thread codecowboy

Thank you.  I am looking into that snippet now.  Does anyone know
whether or not it is easy to integrate the pear datagrid tool into
cake?

Thank you,

codecowboy


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



Re: Pagination using multiple models and custom queries

2006-09-08 Thread AD7six

Hi Codecowboy,

The problem with pulling data from more than one table, is that if it
triggers more than one sql statement you can´t apply a sort to it.
This means that with the execption of belongsTo HasOne sorting queries
becomes "difficult".

What you describe is a grid sorting rather than paginating task; there
is an ajax grid sorter thingy on cakeforge that might do what you want.

Incidentally, if you pass the total to the pagination code I wrote, you
can use it just to spit out the page and sort parameters that were
passed in from the web (or taken from defaults if absent).

HTH,

AD7six


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



Re: Pagination using multiple models and custom queries

2006-09-08 Thread codecowboy


Sohei Okamoto wrote:
> I haven't tried this yet, but I think this is what you are looking for.
> http://wiki.cakephp.org/tutorials:pagination
>
> It looks promising.
>
> Sohei

Thanks Sohei, but we have already looked into that it doesn't seem to
work.  We are looking for a pagination tool that takes in an array and
creates a sortable columns from the array.  The reason we need this is
so that we can query multiple tables as opposed to being locked into
one model.  We think that pear data grid will work but we aren't sure
how easily we can integrate it into cake.

Thank you,

codecowboy


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



Re: Pagination using multiple models and custom queries

2006-09-06 Thread Sohei Okamoto
I haven't tried this yet, but I think this is what you are looking for.http://wiki.cakephp.org/tutorials:pagination
 It looks promising.Sohei

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


Pagination using multiple models and custom queries

2006-09-06 Thread codecowboy

Hi, I'm working on creating an index of a certain models, however I
want to be able to take columns from several tables and be able to sort
and paginate according to any of those columns. I was wondering if
anyone knew the best way to do this. Also, I would like to know if I
could create custom queries, and have it sort and paginate according to
the results of those queries. Thanks.


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



Re: Noob question about Models and custom queries

2006-07-30 Thread DJ Spark

 probably you have a controller 'Projects' , with a action name() inside
 if you take the task name as a variable for the name() action, you
might call the Tasks controller with requestaction()

function name($projectid=null)
{
  if(!projectid)
  {
//finds the project with a specific name
  }
  else
  {
$this->set('tasklist',
$this->requestAction('/tasks/showbyproject/'.$projectid) );
  }
}

 (assuming you have a showbyproject() action to list the tasks of a
given project.)
 this will set a variable in your view , with the 'bare' view of that
action. you might just do an echo in the right place.
 hope it helps :)

 spark

On 7/30/06, Andre <[EMAIL PROTECTED]> wrote:
>
> Hi there. Total noob here, so please be patient :P
>
> I'm developing an application that manages tasks for different
> projects.
> I've been able to have a links of projects displayed, and to retrieve
> the information relative to a specific project, with this link
> structure:
>
> /projects/ (this one finds all the projects)
> /projects/name/ (this one finds the project with a specific name)
>
> Now, since every project has a lot of "tasks", how can I accomplish
> this result:
>
> /projects/name/tasks/ (displays all the tasks for the "name" project)
> If I were coding in normal PHP I'd do a simple query with a WHERE
> clause, but with CakePHP I just don't get how to do that...
>
> Any help will be greatly appreciated :)
>
> Andre
>
>
> >
>


-- 
[web] http://synapsisdi.com.br
[livesets] http://djspark.com.br

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



Noob question about Models and custom queries

2006-07-30 Thread Andre

Hi there. Total noob here, so please be patient :P

I'm developing an application that manages tasks for different
projects.
I've been able to have a links of projects displayed, and to retrieve
the information relative to a specific project, with this link
structure:

/projects/ (this one finds all the projects)
/projects/name/ (this one finds the project with a specific name)

Now, since every project has a lot of "tasks", how can I accomplish
this result:

/projects/name/tasks/ (displays all the tasks for the "name" project)
If I were coding in normal PHP I'd do a simple query with a WHERE
clause, but with CakePHP I just don't get how to do that...

Any help will be greatly appreciated :)

Andre


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



Re: custom queries

2006-05-01 Thread [EMAIL PROTECTED]

$this->Model->execute() can run completely custom queries.

So, you could run "SELECT COUNT(*)" queries directly against the
database and get the results.  Just turn on debugging to see how
specifically MySQL will return the results into array format in
CakePHP.

I used the following query.

$temp = $this->Customer->execute("SELECT LAST_INSERT_ID() from
pe_customers");
$cust_id = $temp[0][0]['last_insert_id()'];


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



Re: custom queries

2006-04-30 Thread Timm

I guess where are talking at cross purposes.
As long as you use the build-in method (with associations etc.) for
retrieving data from the database everything works well.
But I want to use a custom query, where the automatic construction of
table names does not happen, as far as I know.


> I'm all out of fish for today ;)
>
> The code I pasted above is using a Model instance, not a table. It's
> taken from code that I use on more than one DB setup, and using
> prefixes.
>
> By default the table name is the same as the model name but it doesn't
> have to be. You'll find you can modify your DB setup however you want
> (including on the fly if you need) - the answers to all your questions
> are in the wiki (amongst other places).
> 
> Happy coding,
> 
> AD7six


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



Re: custom queries

2006-04-30 Thread AD7six

I'm all out of fish for today ;)

The code I pasted above is using a Model instance, not a table. It's
taken from code that I use on more than one DB setup, and using
prefixes.

By default the table name is the same as the model name but it doesn't
have to be. You'll find you can modify your DB setup however you want
(including on the fly if you need) - the answers to all your questions
are in the wiki (amongst other places).

Happy coding,

AD7six


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



Re: custom queries

2006-04-30 Thread Timm

Using PHP to count the number of comments may be applicable if you do
have small amounts of data. But I would prefer passing the work over to
the MySQL server.

I know that I can use the query method in order to send plain SQL
queries. What I am asking for is a standard method to construct table
names.
I want to use different database configurations with the same
application code. Some of those configurations use the 'prefix'
attribute. If I used plain table names in my SQL queries, the tables
would not always be found.
Does the framework provide a way to access the fully constructed (any
prefixes appended) table names?


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



Re: custom queries

2006-04-30 Thread AD7six

Timm wrote:
> Thanks for your advice. I have already played with associations, but I
> could not figure out, how I can get the number of comments associated
> with each post. (see the query I presented in the initial post
The query you present is quite simple and doesn't really need any
bespoke SQL.

I think this would do it:
//In your Post Model
class Post extends AppModel
{
var $name = 'Post';
var $hasMany = 'Comment';
..

//In controller
$data = $this->Post->findAll();
foreach ($data as $Blog)
{
$NumberOfComments = isset ($data['Comment'])?count($data['Comment']):0;
...

If you do need to do a custom query, use "query"
http://api.cakephp.org/class_model.html#0014cb0f3c55887178b62ce53dbc4733

It's a shame the wiki search isn't working too well, but you'll
probably find the cake search tool useful for such questions
(http://www.cakephp.org/search/index/query)

Cheers,

AD7six


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



Re: custom queries

2006-04-30 Thread Timm

Thanks for your advice. I have already played with associations, but I
could not figure out, how I can get the number of comments associated
with each post. (see the query I presented in the initial post)
In the source code of the CakePHP framework I discovered an attribute
"counterQuery" (part of the hasMany array), but it seems that the
functionality isn't implemented yet.

But to get back to the inital question:
Suppose a certain very complex query cannot be rewritten with the use
of associations: How can I refer to table names in a flexible manner,
so that prefixes are added by the framework automatically?



> Yes - you need to look into associations, but it's not that hard:
> Here's a good starting point
> http://wiki.cakephp.org/tutorials:book_titles.
>
> If you set DEBUG to 2, you will see all the SQL queries at the bottom
> of your page.
> 
> Cheers,
> 
> AD7six


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



Re: custom queries

2006-04-30 Thread AD7six


Timm wrote:
> Could the CakePHP framework build this query internally? (I haven't
> dealt with associations yet)
Yes - you need to look into associations, but it's not that hard:
Here's a good starting point
http://wiki.cakephp.org/tutorials:book_titles.

If you set DEBUG to 2, you will see all the SQL queries at the bottom
of your page.

Cheers,

AD7six


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



Re: custom queries

2006-04-30 Thread Timm

Isn't there a solution?

Could the CakePHP framework build this query internally? (I haven't
dealt with associations yet)


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



custom queries

2006-04-23 Thread Timm

What's the recommended way to construct custom SQL queries? I
specifically want to know how I should get the appropriate table names.
I can get the table name (including any prefixes) of the current model
object by accessing the $this->table variable. But how should I access
the table name of a related table?
Here's an example (this is placed inside the Post model):

$records = $this->query('
SELECT
Post.id,
Post.title,
Post.body,
Post.created,
COUNT(post_id) AS num_comments
FROM posts AS Post
LEFT JOIN post_comments
ON Post.id = post_id
GROUP BY
Post.id
ORDER BY
Post.created DESC');

If I used a query like the one above I would have to change all table
references (posts, post_comments) each time I change the table name or
the global table prefix.
But what's the best way to build these table names?
I came up with the following code which is not a very satisfying
solution:

$postComment = new PostComment();

$records = $this->query('
SELECT
Post.id,
Post.title,
Post.body,
Post.created,
COUNT(post_id) AS num_comments
FROM '.$this->table.' AS Post
LEFT JOIN '.$postComment->table.'
ON Post.id = post_id
GROUP BY
Post.id
ORDER BY
Post.created DESC');

Here I'm constructing a PostComment model just in order to access its
table attribute.
Any alternatives?


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