Question

I want to save 2+ datas in a model hasMany trough. But this is not saving.

 $data[] = array('User' => array('id' => 5), 'Solicitation' => array('id' => $this->Solicitation->id));
$data[] = array('User' => array('id' => 6), 'Solicitation' => array('id' => $this->Solicitation->id));
debug($data);
$this->SolicitationUser->saveAll($data);

Result of debug($data)

array(
(int) 0 => array(
    'User' => array(
        'id' => (int) 5
    ),
    'Solicitation' => array(
        'id' => '70'
    )
),
(int) 1 => array(
    'User' => array(
        'id' => (int) 6
    ),
    'Solicitation' => array(
        'id' => '70'
    )
)
)
Was it helpful?

Solution

It's hard to tell what you're going after, since there's little description, but I assume you'd want it more like this to save two rows in your HasMany Through table:

array(
    (int) 0 => array(
        'user_id' => (int) 5
        'solicitation_id' => '70'
    ),
    (int) 1 => array(
        'user_id' => (int) 6
        'solicitation_id' => '70'
    )
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top