Re: Easy Query Seems Difficult to Fire

2011-06-15 Thread Jeremy Burns | Class Outfit
Are you trying to do an inner join where you only pull back contacts who belong 
to a company?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 15 Jun 2011, at 17:44, Zuha wrote:

 Seems like this should be easy, and maybe I'm just missing how to do
 it, but I want to execute the following query. [preferrably using
 find('list')]
 
 SELECT `Contact`.`id`, `Contact`.`name` FROM `contacts` AS `Contact`,
 `contact_companies` AS `ContactCompany` WHERE `Contact`.`id` =
 `ContactCompany`.`contact_id` ORDER BY `Contact`.`name` ASC
 
 ContactCompany belongsTo Contact
 
 That query returns the exact information I want, but without query(),
 I don't see how to do it.
 
 -- 
 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: Easy Query Seems Difficult to Fire

2011-06-15 Thread Zuha
Close... select where we only pull back contacts where the company
belongsTo contact



On Jun 15, 3:00 pm, Jeremy Burns | Class Outfit
jeremybu...@classoutfit.com wrote:
 Are you trying to do an inner join where you only pull back contacts who 
 belong to a company?

 Jeremy Burns
 Class Outfit

 jeremybu...@classoutfit.comhttp://www.classoutfit.com

 On 15 Jun 2011, at 17:44, Zuha wrote:







  Seems like this should be easy, and maybe I'm just missing how to do
  it, but I want to execute the following query. [preferrably using
  find('list')]

  SELECT `Contact`.`id`, `Contact`.`name` FROM `contacts` AS `Contact`,
  `contact_companies` AS `ContactCompany` WHERE `Contact`.`id` =
  `ContactCompany`.`contact_id` ORDER BY `Contact`.`name` ASC

  ContactCompany belongsTo Contact

  That query returns the exact information I want, but without query(),
  I don't see how to do it.

  --
  Our newest site for the community: CakePHP Video 
  Tutorialshttp://tv.cakephp.org
  Check out the new CakePHP Questions sitehttp://ask.cakephp.organd 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 
  athttp://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: Easy Query Seems Difficult to Fire

2011-06-15 Thread Zuha
INNER was the word I needed to remember to get an alternative to
work.


For other people here's what the end query (which returns the same as
the above query) turned out to be.

SELECT `Contact`.`id`, `Contact`.`name` FROM `contacts` AS `Contact`
INNER JOIN contact_companies AS `ContactCompany` ON
(`ContactCompany`.`contact_id` = `Contact`.`id`) WHERE 1 = 1 ORDER BY
`Contact`.`name` ASC


and the Cakephp way is (in my Contact model)

$this-find('list', array(
 'joins' = array(array(
'table' = 'contact_companies',
'alias' = 'ContactCompany',
'type' = 'INNER',
'conditions' = array(
'ContactCompany.contact_id = Contact.id',
),
)),
'order' = 'Contact.name'));


(I typed that out, so don't shoot me if I'm missing a parenthesis or
something)




On Jun 15, 4:46 pm, Zuha zuha-test...@razorit.com wrote:
 Close... select where we only pull back contacts where the company
 belongsTo contact

 On Jun 15, 3:00 pm, Jeremy Burns | Class Outfit







 jeremybu...@classoutfit.com wrote:
  Are you trying to do an inner join where you only pull back contacts who 
  belong to a company?

  Jeremy Burns
  Class Outfit

  jeremybu...@classoutfit.comhttp://www.classoutfit.com

  On 15 Jun 2011, at 17:44, Zuha wrote:

   Seems like this should be easy, and maybe I'm just missing how to do
   it, but I want to execute the following query. [preferrably using
   find('list')]

   SELECT `Contact`.`id`, `Contact`.`name` FROM `contacts` AS `Contact`,
   `contact_companies` AS `ContactCompany` WHERE `Contact`.`id` =
   `ContactCompany`.`contact_id` ORDER BY `Contact`.`name` ASC

   ContactCompany belongsTo Contact

   That query returns the exact information I want, but without query(),
   I don't see how to do it.

   --
   Our newest site for the community: CakePHP Video 
   Tutorialshttp://tv.cakephp.org
   Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp 
   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 
   athttp://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