0

I need your help because I can't extract results as I want from my query result without doing a foreach loop.

My query returns an array like this one :

array(
(int) 0 => array(
    'Event' => array(
        'id' => '1',
        'title' => 'Event title',
    ),
    'ShopstaffR' => array(
        (int) 0 => array(
            'id' => '1',
            'event_id' => '1',
            'shopstaff_id' => '1'
        ),
        (int) 1 => array(
            'id' => '2',
            'event_id' => '1',
            'shopstaff_id' => '2'
        )
    ),
    'Shopstaff' => array(
        (int) 0 => array(
            'id' => '1',
            'name' => 'Ben',
            'EventsShopstaff' => array(
                'id' => '1',
                'event_id' => '1',
                'shopstaff_id' => '1'
            )
        ),
        (int) 1 => array(
            'id' => '2',
            'name' => 'Alex',
            'EventsShopstaff' => array(
                'id' => '2',
                'event_id' => '1',
                'shopstaff_id' => '2'
            )
        )
    )
),
(int) 1 => array(
ETC ....

Event model has an HABTM relation with the Shopstaff model and I would like to extract an array as this one :

array(
(int) 0 => array(
    'Event' => array(
        'id' => '1',
        'title' => 'Event title, Shopstaff: Ben, Alex',
    ),
),
(int) 1 => array(
ETC ....

The problem is that I can't manage to do that with set::combine method because I don't know how many ShopStaff there will be.

Any idea ?

1 Answers1

0

try this or something similar

$var - array();   
$var['Event'] = Hash::extract( $queryResult, '{n}.Event' );

why dont you just pull the model you want and unbind other models from your query? Set::combine uses a foreach, which can be inefficient in some cases

Ayo Akinyemi
  • 792
  • 4
  • 7
  • Because I need the Shopstaff Model, I would like to concatenate the Shopstaff members with the event title, and for that I need both. – nicolecoco02 Oct 09 '13 at 14:59