Hi Ivan,

Set your model associations using belongsTo, hasOne, etc and then use the 
Containable behaviour.

The question I posted should help: 
http://groups.google.com/group/cake-php/browse_thread/thread/4d412591e87408a/7ab27dd679d60605?lnk=gst&q=trouble+linking+models#7ab27dd679d60605

Of note: setting the recursive value enabled the linking of models of deeper 
levels.

Clint


> Hi,
> Maybe someone can help me with this...
> The tables are linked this way:
> http://dl.dropbox.com/u/52896949/Screen%20Shot%202012-01-22%20at%201.03.03%20AM.png
> What i need is:
> Find all Events that a user is linked with.
> Witch means: that a user is "owner" (the Events.user_id) or that the
> user is staff of (Table Staffs).
> So, what i have made is:
> ----
> public function getEventsOf($User_id){
> 
>               $conditions = array(
>                       'Event.status' => 'active',
>                       'AND' => array(
>                               'OR' => array(
>                                       'Event.user_id' => $User_id,
>                                       'OR'=>array(
>                                               'AND' => array(
>                                                       'Event.id = 
> Staff.user_id',
>                                                       'Staff.user_id' => 
> $User_id,
>                                               ),
>                                       ),
>                               ),
>                       ),
>               );
>               $users = $this->find('all', array(
>                       'conditions'=> $conditions,
>                       'recursive' => 0) );
> 
>               return $users;
>       }
> 
> -----
> But a error shows up:
> -----
> Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column
> 'Staff.user_id' in 'where clause'
> SQL Query: SELECT `Event`.`id`, `Event`.`user_id`, `Event`.`title`,
> `Event`.`description`, `Event`.`country`, `Event`.`state`,
> `Event`.`city`, `Event`.`date_start`, `Event`.`date_end`,
> `Event`.`pin`, `Event`.`pros_cons`, `Event`.`status`,
> `Event`.`created`, `Event`.`modified`, `User`.`id`,
> `User`.`first_name`, `User`.`last_name`, `User`.`email`,
> `User`.`password`, `User`.`username`, `User`.`country`,
> `User`.`state`, `User`.`status`, `User`.`created`, `User`.`modified`
> FROM `events` AS `Event` LEFT JOIN `users` AS `User` ON
> (`Event`.`user_id` = `User`.`id`) WHERE `Event`.`status` = 'active'
> AND ((`Event`.`user_id` = 12) OR (((`Event`.`id` = `Staff`.`user_id`)
> AND (`Staff`.`user_id` = 12))))
> ----
> 
> What do i do?
> Thanks...
> Ivan
> 
> -- 
> 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
> [email protected] 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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to