habtm - need some clarification

2009-02-28 Thread Dhana

I have a groups, users and tasks models.

Groups has a HABTM to users.
Users has a HABTM to groups.
Users has many tasks.

From the tasks model, I am trying to find out which group the user
belongs to. Once I have this information, I plan to put into a session
variable so I only need to query this once while the user is in
session.

But, how do I make this query efficiently?





--~--~-~--~~~---~--~~
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: habtm - need some clarification

2009-02-28 Thread mscdex

On Feb 28, 1:30 pm, Dhana sldh...@gmail.com wrote:
 But, how do I make this query efficiently?

One solution would be to use the Containable behavior with the User
model. Then you can find what groups the user belongs to by doing a
find and including a 'contain' option which is an array containing the
associated models you are interested in (in this case, 'Group').

So for example (in the User model), something like:
function getGroups($userID) {
   return $this-find('first', array('conditions' = array
('User.id' = $userID), 'contain' = array('Group')));
}
--~--~-~--~~~---~--~~
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: habtm - need some clarification

2009-02-28 Thread Marcelo Andrade

On Sat, Feb 28, 2009 at 3:30 PM, Dhana sldh...@gmail.com wrote:

 I have a groups, users and tasks models.

 Groups has a HABTM to users.
 Users has a HABTM to groups.
 Users has many tasks.

 From the tasks model, I am trying to find out which group the user
 belongs to. Once I have this information, I plan to put into a session
 variable so I only need to query this once while the user is in
 session.

 But, how do I make this query efficiently?

I'm not sure if I understood your question.  On your
controller, set the recursive property to the Task
model to 2 and get the full resultset with a
find('all') method, like

$this-Task-recursive= 2;
$all= $this-Task-find('all');

Be sure that your models are correctly associated.

Best regards.

--
MARCELO DE F. ANDRADE (aka eleKtron)
Belem, PA, Amazonia, Brazil
Linux User #221105

[...@pará ~]# links http://pa.slackwarebrasil.org/

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