On Feb 6, 7:57 pm, "abergs.and...@gmail.com" <abergs.and...@gmail.com>
wrote:
> Hello!
>
> Im been at this for hours and hanging in the IRC channel, without
> getting the final solution.
> I want to share events between users...
>
> **I have these relations:
> User hasmany Event
> Event HABTM User
>
> **I have these tables
> [events]
> -id
> -user_id
> -title
>
> [users]
> -id
> -email
> -and some other columns thats not interesting
>
> [events_users]
> -id
> -event_id
> -user_id
> -group_id (not used at the moment)

It sounds like you just need the User HABTM Events. Having a user_id
in Event is redundant since you have the HABTM relationship. Also, I
highly suggest removing the 'id' field in events_users and simply make
both 'event_id' and 'user_id' primary keys.

> What i want to do with this array is that i want to collect those
> Events that has user_id = 12. Which normally is 'id':9 and 26. Though
> id 23 is shared to user_id 12. Therefore i want to collect it aswell!

If you're just wanting events for user id of 12, then try this
(provided your relationships are defined properly in the model): $this-
>set('events', $this->Event->find('all', array('conditions' => array
('User.id' => 12), 'recursive' => 1)));

If you are intentionally wanting all records to begin with and are
looking to grab certain parts of the array, look into the Set Utility
Library: http://book.cakephp.org/view/640/Set
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to