This comes very close to what I'm looking for, but the first find that
I wrote (it isn't an exact copy of your code but should be equal):
$options = array(
'conditions' => array(
'ProjectsUser.user_id' => 12
)
);
debug($this->Project->ProjectsUser->find('list',$options));
prints the unique id:s of the matched rows in the projects_users
table. Unfortunately, it gives me a list of;
[0] => 61
[1] => 67
but these id:s don't exist in the Project-table.
Just a small example of three rows of actual values in the
projects_users table;
____projects_users____
id | user_id | project_id
61| 12 | 2
67 | 12 | 7
68 | 13 | 5
Now, I get the id-column when doing the suggested find and this I
can't match to the Project-table id's. I guess what I want are the
project_id's from the project_users table to be able to match this
right.
I'll go back and fiddle a bit more with this but to come with
suggestions.
This worked almost right out of the box, I'm impressed! Thank you for
these and any further comments!
On Jun 7, 10:02 pm, vekija <[email protected]> wrote:
> The easiest way that comes to mine mind would be to get the ids of the
> projects you are involved at first and then pass those as condition in
> the before mentioned find call.
>
> Something like...
>
> $this->loadModel('ProjectsUser');
>
> $ids = $this->ProjectsUser->find('list', array('conditions' =>
> array('ProjectsUser.user_id => $yourId)));
>
> $projects = $this->Project->find('all', array(
> 'contain' => array(
> 'Group' => array('User')
> ),
> 'conditions => array('Project.id' => array_keys($ids))
> ));
>
> there are probably other ways of doing this, but I would have to think
> and test before I recommend them. :)
>
> Cheers
>
> On Jun 7, 9:03 pm, DrLaban <[email protected]> wrote:
>
>
>
> > Oooh! That's pretty awesome, and it seems to work like a charm,
> > thanks!
>
> > Just one more question on this subject. This involves a bit more
> > trickery I believe;
>
> > I'd also like to be able to view all the Groups/Users for all the
> > projects I'm involved at. This would look something like
> > [Project 1]
> > [Group 1]
> > [User 2]
> > [User 3]
> > [User 4]
> > [Group 10]
> > [User 1]
> > [User 3]
> > [Project 2]
> > [Group 25]
> > [User 1]
> > [User 3]
> > [User 7]
>
> > Now, the information about what projects I'm involved at is stored in
> > projects_users. I guess I somehow have to use this information to be
> > able to present it in the above described way? Otherwise I'm not sure
> > as to how I could first filter out all the projects I'm involved with
> > and then go hunt for the groups and users. Any insights on this matter
> > is really appreciated.
>
> > Thank you in advance!
>
> > On Jun 7, 3:26 pm, vekija <[email protected]> wrote:
>
> > > You can try Containable behavior.
>
> > > In models put
>
> > > var $actsAs = array('Containable');
>
> > > and then in the controller....
>
> > > $this->Project->find('all', array('contain' => array('Group' =>
> > > array('User'))));
>
> > > you can find out more about the Containable behavior in the cook
> > > bookhttp://book.cakephp.org/view/1323/Containable
>
> > > On Jun 7, 2:54 pm, DrLaban <[email protected]> wrote:
>
> > > > My setup is pretty straightforward;
> > > > User HABTM Group
> > > > Group HABTM Project
> > > > Project HABTM User
>
> > > > I would like to produce a find-query that takes a single project-id
> > > > and builds a hierarchic contact list, in which the users belong to
> > > > their respective group(s).
>
> > > > Something along these lines:
> > > > [Project 1]
> > > > [Group 1]
> > > > [User 1]
> > > > [User 5]
> > > > [Group 2]
> > > > [User 1]
> > > > [User 2]
> > > > [User 3]
> > > > [Group 4]
> > > > [User 3]
> > > > [User 4]
> > > > ...
>
> > > > Is this possible and if so, how? All I've been able to produce is
> > > > something of a flat structure where I can't match the user to a group;
> > > > [Project 1]
> > > > [User 1]
> > > > [User 3]
> > > > [User 4]
> > > > [User 6]
> > > > [Group 1]
> > > > [Group 3]
> > > > [Group 4]
>
> > > > This is produced when I do;
> > > > $this->Project->find('all');
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 [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