Wednesday, March 31, 2010

Re: $this->...->query("...");

Hey my complete function is:

$user = $this->Auth->user();
$this->Planet->recursive = 0;

$planets = $this->Planet->query("SELECT *
FROM planets AS Planet
LEFT OUTER JOIN buildings AS
Building
ON (Planet.id =
Building.planet_id)
WHERE Building.user_id=".
$user['User']['id'].";");

$this->set('planets',$planets);

greets
Dom

On 31 Mrz., 19:40, John Andersen <j.andersen...@gmail.com> wrote:
> We need more information! How are you realizing your query - are you
> using CakePHP models find or query method?
> Please show the code where you are using your query!
> Enjoy,
>    John
>
> On Mar 31, 6:18 pm, Dominik Kukacka <dominik.kuka...@gmail.com> wrote:
>
>
>
> > Hey everyone,
>
> > i tried to make an join query on two tables!
>
> > my query is:
>
> >    SELECT *
> >    FROM planets AS Planet
> >    LEFT OUTER JOIN buildings AS Building  ON (Planet.id =
> > Building.planet_id)
> >    WHERE Building.user_id=1;
>
> > so, the query works well in my PMA and in Workbench (CL),
> > but in cakePHP it makes some additional querys:
>
> > SELECT COUNT(*) AS `count`
> > FROM `planets` AS `Planet`
> > WHERE ((Planet IN ('1', 'Planet Erde', '100', '1', '100', '10', '10',
> > '10', '[1,20,20]', '400'))
> > AND (Building IN ('1', '1', '1', 'command_center', '1', '[25,25]')))
> > AND ((Planet IN ('2', 'Mond', '100', '0', '100', '0', '10', '-5',
> > '[1,21,20]', '100'))
> > AND (Building IN ('3', '2', '1', 'explorer_small', '2', '[10,4]')))
>
> > SELECT `Planet`.`id`, `Planet`.`name`, `Planet`.`space`,
> > `Planet`.`space_used`, `Planet`.`healthpoints`, `Planet`.`oil`,
> > `Planet`.`water`, `Planet`.`heat`, `Planet`.`coordinates`,
> > `Planet`.`size`
> > FROM `planets` AS `Planet`
> > WHERE ((Planet IN ('1', 'Planet Erde', '100', '1', '100', '10', '10',
> > '10', '[1,20,20]', '400'))
> > AND (Building IN ('1', '1', '1', 'command_center', '1', '[25,25]')))
> > AND ((Planet IN ('2', 'Mond', '100', '0', '100', '0', '10', '-5',
> > '[1,21,20]', '100'))
> > AND (Building IN ('3', '2', '1', 'explorer_small', '2', '[10,4]')))
> > LIMIT 20
>
> > This doesn relly can work because of: Planet IN ('1', 'Planet Erde',
> > '100', '1', '100'.. doesn't really make sense; ey?
> > Why does cakePHP do that?
>
> > greets from Vienna
> > Dom

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: