Using the "group" option solved this issue. Thanks.

~Michael

On Sun, Feb 10, 2013 at 11:09 AM, 清水紘己 <[email protected]> wrote:

> Perhaps you can't get hasMany records(Characters) at once with `join`
> option.
> Use bindModel() etc.
> See:
> http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#creating-and-destroying-associations-on-the-fly
>
>
> 2013/2/11 清水紘己 <[email protected]>
>
>> You should specify event_id or so to `group` option for GROUP BY when
>> using joins with multiple records.
>> It is SQL matter.
>>
>>
>> 2013/2/11 Michael Gaiser <[email protected]>
>>
>>> I want to know what I can do so it only returns the event once. Thanks.
>>>
>>>
>>> So here is my find parameters.
>>>
>>> $this->Event->find('all', array(
>>>  'conditions'=>array('Location.id'=>4),
>>> 'joins'=>array(
>>>  array('table' => 'characters_events',
>>> 'alias' => 'Characters',
>>>  'type' => 'inner',
>>> 'conditions' => array(
>>>  'Event.id = Characters.event_id',
>>> )
>>> ),
>>>  ),
>>> 'contain'=>array(
>>> 'Location'=>array('id', 'name', 'parent_id', 'longitude',
>>> 'latitude','zoom'),
>>>  'EventsType'=>array('id', 'name',
>>> 'Role'=>array('id', 'name', 'events_type_id'),
>>>  ),
>>> 'Characters'=>array('id', 'role_id', 'character_id', 'description',
>>>  'Character'=>array('id', 'name'),
>>> 'Role'=>array('id', 'name'),
>>>  ),
>>> ),
>>> 'fields'=>array(
>>>  'id',
>>> 'event_type_id',
>>> 'chronicle_id',
>>>  'location_id',
>>> 'start_date',
>>> 'end_date',
>>>  'description',
>>> 'created',
>>> 'modified'
>>>  );
>>> ));
>>>
>>>
>>> And here is what it returns: (Its a bit long...  Basically it shows the
>>> same event record several times)
>>>
>>> array(
>>>     (int) 0 => array(
>>>             'Event' => array(
>>>                     'id' => '1',
>>>                     'event_type_id' => '2',
>>>                     'chronicle_id' => '1',
>>>                     'location_id' => '4',
>>>                     'start_date' => null,
>>>                     'end_date' => '735259',
>>>                     'description' => 'The birth of phobos was a great 
>>> event..',
>>>                     'created' => '2013-01-25 22:13:32',
>>>                     'modified' => '2013-01-27 15:25:26'
>>>             ),
>>>             'EventsType' => array(
>>>                     'id' => '2',
>>>                     'name' => 'Birth',
>>>                     'Role' => array(
>>>                             (int) 0 => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 1 => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 2 => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn',
>>>                                     'events_type_id' => '2'
>>>                             )
>>>                     )
>>>             ),
>>>             'Location' => array(
>>>                     'id' => '4',
>>>                     'name' => 'San Francisco',
>>>                     'parent_id' => '3',
>>>                     'longitude' => '-122.44',
>>>                     'latitude' => '37.7488',
>>>                     'zoom' => '11'
>>>             ),
>>>             'Characters' => array(
>>>                     (int) 0 => array(
>>>                             'id' => '1',
>>>                             'role_id' => '7',
>>>                             'character_id' => '1',
>>>                             'description' => 'Love to live',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '1',
>>>                                     'name' => 'Phobos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     ),
>>>                     (int) 1 => array(
>>>                             'id' => '2',
>>>                             'role_id' => '9',
>>>                             'character_id' => '26',
>>>                             'description' => 'Yo Dad!',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '26',
>>>                                     'name' => 'Alphonse Heisenberg'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father'
>>>                             )
>>>                     ),
>>>                     (int) 2 => array(
>>>                             'id' => '3',
>>>                             'role_id' => '8',
>>>                             'character_id' => '41',
>>>                             'description' => 'Hi Mom',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '41',
>>>                                     'name' => 'Roslin Bricker'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother'
>>>                             )
>>>                     ),
>>>                     (int) 3 => array(
>>>                             'id' => '4',
>>>                             'role_id' => '7',
>>>                             'character_id' => '2',
>>>                             'description' => 'Hey Bro',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '2',
>>>                                     'name' => 'Deimos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     )
>>>             )
>>>     ),
>>>     (int) 1 => array(
>>>             'Event' => array(
>>>                     'id' => '1',
>>>                     'event_type_id' => '2',
>>>                     'chronicle_id' => '1',
>>>                     'location_id' => '4',
>>>                     'start_date' => null,
>>>                     'end_date' => '735259',
>>>                     'description' => 'The birth of phobos was a great 
>>> event..',
>>>                     'created' => '2013-01-25 22:13:32',
>>>                     'modified' => '2013-01-27 15:25:26'
>>>             ),
>>>             'EventsType' => array(
>>>                     'id' => '2',
>>>                     'name' => 'Birth',
>>>                     'Role' => array(
>>>                             (int) 0 => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 1 => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 2 => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn',
>>>                                     'events_type_id' => '2'
>>>                             )
>>>                     )
>>>             ),
>>>             'Location' => array(
>>>                     'id' => '4',
>>>                     'name' => 'San Francisco',
>>>                     'parent_id' => '3',
>>>                     'longitude' => '-122.44',
>>>                     'latitude' => '37.7488',
>>>                     'zoom' => '11'
>>>             ),
>>>             'Characters' => array(
>>>                     (int) 0 => array(
>>>                             'id' => '1',
>>>                             'role_id' => '7',
>>>                             'character_id' => '1',
>>>                             'description' => 'Love to live',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '1',
>>>                                     'name' => 'Phobos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     ),
>>>                     (int) 1 => array(
>>>                             'id' => '2',
>>>                             'role_id' => '9',
>>>                             'character_id' => '26',
>>>                             'description' => 'Yo Dad!',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '26',
>>>                                     'name' => 'Alphonse Heisenberg'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father'
>>>                             )
>>>                     ),
>>>                     (int) 2 => array(
>>>                             'id' => '3',
>>>                             'role_id' => '8',
>>>                             'character_id' => '41',
>>>                             'description' => 'Hi Mom',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '41',
>>>                                     'name' => 'Roslin Bricker'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother'
>>>                             )
>>>                     ),
>>>                     (int) 3 => array(
>>>                             'id' => '4',
>>>                             'role_id' => '7',
>>>                             'character_id' => '2',
>>>                             'description' => 'Hey Bro',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '2',
>>>                                     'name' => 'Deimos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     )
>>>             )
>>>     ),
>>>     (int) 2 => array(
>>>             'Event' => array(
>>>                     'id' => '1',
>>>                     'event_type_id' => '2',
>>>                     'chronicle_id' => '1',
>>>                     'location_id' => '4',
>>>                     'start_date' => null,
>>>                     'end_date' => '735259',
>>>                     'description' => 'The birth of phobos was a great 
>>> event..',
>>>                     'created' => '2013-01-25 22:13:32',
>>>                     'modified' => '2013-01-27 15:25:26'
>>>             ),
>>>             'EventsType' => array(
>>>                     'id' => '2',
>>>                     'name' => 'Birth',
>>>                     'Role' => array(
>>>                             (int) 0 => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 1 => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 2 => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn',
>>>                                     'events_type_id' => '2'
>>>                             )
>>>                     )
>>>             ),
>>>             'Location' => array(
>>>                     'id' => '4',
>>>                     'name' => 'San Francisco',
>>>                     'parent_id' => '3',
>>>                     'longitude' => '-122.44',
>>>                     'latitude' => '37.7488',
>>>                     'zoom' => '11'
>>>             ),
>>>             'Characters' => array(
>>>                     (int) 0 => array(
>>>                             'id' => '1',
>>>                             'role_id' => '7',
>>>                             'character_id' => '1',
>>>                             'description' => 'Love to live',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '1',
>>>                                     'name' => 'Phobos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     ),
>>>                     (int) 1 => array(
>>>                             'id' => '2',
>>>                             'role_id' => '9',
>>>                             'character_id' => '26',
>>>                             'description' => 'Yo Dad!',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '26',
>>>                                     'name' => 'Alphonse Heisenberg'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father'
>>>                             )
>>>                     ),
>>>                     (int) 2 => array(
>>>                             'id' => '3',
>>>                             'role_id' => '8',
>>>                             'character_id' => '41',
>>>                             'description' => 'Hi Mom',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '41',
>>>                                     'name' => 'Roslin Bricker'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother'
>>>                             )
>>>                     ),
>>>                     (int) 3 => array(
>>>                             'id' => '4',
>>>                             'role_id' => '7',
>>>                             'character_id' => '2',
>>>                             'description' => 'Hey Bro',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '2',
>>>                                     'name' => 'Deimos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     )
>>>             )
>>>     ),
>>>     (int) 3 => array(
>>>             'Event' => array(
>>>                     'id' => '1',
>>>                     'event_type_id' => '2',
>>>                     'chronicle_id' => '1',
>>>                     'location_id' => '4',
>>>                     'start_date' => null,
>>>                     'end_date' => '735259',
>>>                     'description' => 'The birth of phobos was a great 
>>> event..',
>>>                     'created' => '2013-01-25 22:13:32',
>>>                     'modified' => '2013-01-27 15:25:26'
>>>             ),
>>>             'EventsType' => array(
>>>                     'id' => '2',
>>>                     'name' => 'Birth',
>>>                     'Role' => array(
>>>                             (int) 0 => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 1 => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother',
>>>                                     'events_type_id' => '2'
>>>                             ),
>>>                             (int) 2 => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn',
>>>                                     'events_type_id' => '2'
>>>                             )
>>>                     )
>>>             ),
>>>             'Location' => array(
>>>                     'id' => '4',
>>>                     'name' => 'San Francisco',
>>>                     'parent_id' => '3',
>>>                     'longitude' => '-122.44',
>>>                     'latitude' => '37.7488',
>>>                     'zoom' => '11'
>>>             ),
>>>             'Characters' => array(
>>>                     (int) 0 => array(
>>>                             'id' => '1',
>>>                             'role_id' => '7',
>>>                             'character_id' => '1',
>>>                             'description' => 'Love to live',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '1',
>>>                                     'name' => 'Phobos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     ),
>>>                     (int) 1 => array(
>>>                             'id' => '2',
>>>                             'role_id' => '9',
>>>                             'character_id' => '26',
>>>                             'description' => 'Yo Dad!',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '26',
>>>                                     'name' => 'Alphonse Heisenberg'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '9',
>>>                                     'name' => 'Father'
>>>                             )
>>>                     ),
>>>                     (int) 2 => array(
>>>                             'id' => '3',
>>>                             'role_id' => '8',
>>>                             'character_id' => '41',
>>>                             'description' => 'Hi Mom',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '41',
>>>                                     'name' => 'Roslin Bricker'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '8',
>>>                                     'name' => 'Mother'
>>>                             )
>>>                     ),
>>>                     (int) 3 => array(
>>>                             'id' => '4',
>>>                             'role_id' => '7',
>>>                             'character_id' => '2',
>>>                             'description' => 'Hey Bro',
>>>                             'event_id' => '1',
>>>                             'Character' => array(
>>>                                     'id' => '2',
>>>                                     'name' => 'Deimos'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '7',
>>>                                     'name' => 'Newborn'
>>>                             )
>>>                     )
>>>             )
>>>     ),
>>>     (int) 4 => array(
>>>             'Event' => array(
>>>                     'id' => '4',
>>>                     'event_type_id' => '9',
>>>                     'chronicle_id' => '1',
>>>                     'location_id' => '4',
>>>                     'start_date' => '680853',
>>>                     'end_date' => '691690',
>>>                     'description' => 'Moving to San Francisco',
>>>                     'created' => '2013-01-27 16:36:58',
>>>                     'modified' => '2013-01-27 16:40:54'
>>>             ),
>>>             'EventsType' => array(
>>>                     'id' => '9',
>>>                     'name' => 'Relocate',
>>>                     'Role' => array(
>>>                             (int) 0 => array(
>>>                                     'id' => '19',
>>>                                     'name' => 'Traveller',
>>>                                     'events_type_id' => '9'
>>>                             )
>>>                     )
>>>             ),
>>>             'Location' => array(
>>>                     'id' => '4',
>>>                     'name' => 'San Francisco',
>>>                     'parent_id' => '3',
>>>                     'longitude' => '-122.44',
>>>                     'latitude' => '37.7488',
>>>                     'zoom' => '11'
>>>             ),
>>>             'Characters' => array(
>>>                     (int) 0 => array(
>>>                             'id' => '16',
>>>                             'role_id' => '19',
>>>                             'character_id' => '22',
>>>                             'description' => 'This trip was much more 
>>> enjoyable.',
>>>                             'event_id' => '4',
>>>                             'Character' => array(
>>>                                     'id' => '22',
>>>                                     'name' => 'Lucas Boont'
>>>                             ),
>>>                             'Role' => array(
>>>                                     'id' => '19',
>>>                                     'name' => 'Traveller'
>>>                             )
>>>                     )
>>>             )
>>>     )
>>> )
>>>
>>>  --
>>> Like Us on FaceBook https://www.facebook.com/CakePHP
>>> Find us on Twitter http://twitter.com/CakePHP
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to