I tried the suggested change to the "find" call, as follows:
$options = $this->Site->find('list',
array(
'fields'=>array('Site.id', 'Site.title'),
'conditions'=>array('SiteUser.id'=>'1')
)
);
However, it resulted in the following error:
Warning (512): SQL Error: 1054: Unknown column 'SiteUser.id' in
'where clause'
The follow SQL was generated, showing that the join was not created:
Query: SELECT `Site`.`id`, `Site`.`title` FROM `sites` AS
`Site` WHERE `SiteUser`.`id` = 7
I have the Relationship setup in the Site Model as follows:
var $hasMany = array(
'SiteUser' => array('className' => 'SiteUser',
'foreignKey' => 'site_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
I have the Relationship setup in the SiteUser Model as follows:
var $belongsTo = array(
'Site' => array('className' => 'Site',
'foreignKey' => 'site_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
Am I misunderstanding/missing something?
Thanks in advance for any assistance.
On Nov 24, 1:48 am, Smelly_Eddie <[EMAIL PROTECTED]> wrote:
> This is a simple relationship, I think your missing something.
>
> $this->find('list', array('fields'=>array
> ('Site.id','Site.title'),'conditions'=>array('SiteUser.id=1'))
>
> THis will require the recursive attribute to be 0 or higher I think.
>
> On Nov 23, 12:03 am, pkclarke <[EMAIL PROTECTED]> wrote:
>
> > I have the following tables:
>
> > sites
> > - id
> > - title
>
> > site_users
> > - id
> > - site_id
> > - user_id
>
> > How do I construct a "find()" to retrieve equivalent of the following
> > query:
>
> > SELECT a.id, a.title FROM sites a, site_users b WHERE a.id = b.site_id
> > AND b.user_id = 1;
>
> > I tried "find('list', array('fields'=>array('SiteUser.site_id',
> > 'SiteUser.Site.title')))" but nothing is that easy ;-)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---