It runs smooth.
Thought i tell you what i did:
==this is my event controlller
var $uses = array('User');
function show() {
$this->set('events', $this->User->find('all', array
('conditions'=>array('id' => $this->Auth->user('id')))));
}
==Relations
User hasMany Event
User HABTM Event
Event HABTM User
==The View
<table>
<?php foreach ($events[0]['Event'] as $key): ?>
<tr><td><?php echo $key['title'];?></td></tr>
<?php endforeach;
?>
</table>
I really hopes this can help others, thanks for the help guys! :)
On 7 Feb, 13:03, dyml <[email protected]> wrote:
> Okey, i have done that know.
> Though im getting a SQL error that is shouldn't get:
> Warning (512): SQL Error: 1054: Unknown column 'EventsUsers.user_id'
> in 'where clause' [CORE\cake\libs\model\datasources\dbo_source.php,
> line 514]
>
> Query: SELECT `Event`.`id`, `Event`.`user_id`, `Event`.`title` FROM
> `events` AS `Event` WHERE `EventsUsers`.`user_id` = 12
>
> This is using this code in my controller:
> $this->set('events', $this->Event->find('all', array(
> 'conditions'=>array('EventsUsers.user_id'=>'12')
> )));
>
> the user HABTM Events. though i kept the Event.user_id.
>
> Events are similiar to "ToDo-notes". I want to create my own todo's
> like "buy the newspaper". But my roomate might just share me a event/
> note that says "Buy Milk!".
> buy the newspaper shouldn't be in the EventUser table while "Buy Milk"
> should. And then i still need Event.user_id.
>
> btw: I dont have a model for EventUser, do i need one?
>
> On 7 Feb, 11:11, WebbedIT <[email protected]> wrote:
>
> > First things first, your relationships are a bit mixed up ... both
> > models should HABTM each other, you're confusing things by trying to
> > create User hasMany Event. Remove users_id from events table, specify
> > that User HABTM Event and rely on the join table to relate things.
>
> > Not sure why mscdex advises removing the id field from the join table,
> > I include one in all my join tables without issue, but happy for
> > mscdex to elaborate and inform us of some performance improvement that
> > may cause :)
>
> > Onto your question about the data fetched by your find call. When
> > everything is linked by HABTM you can do the following find
>
> > $this->Event->find('all', array(
> > 'conditions'=>array('EventsUsers.user_id'=>'12')
> > ));
>
> > It's the confusion of relating users to events in two different ways
> > which makes your query difficult .. once you link them by HABTM alone
> > it becomes easy.
>
> > Paul.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---