Pergunta

Below is the association, the save call, and the data going to the save. It generates the UPDATE query for Event, but there are no queries generated to save the associated EventInstance.

The EventInstance data is created in the Event's beforeSave().

It says it's saving fine - no validation errors..etc. And I have no validation array on the EventInstance model anyway. I also checked and my table doesn't have any issues as far as fields not allowing null...etc. - I tested by setting everything as allow null.

I have no idea - this should be so simple - I've done it 500 times before, but for this one, I'm apparently missing something.

// Event model --------------------------
public $hasMany = array(
    'EventInstance' => array(
        'dependent' => true,
        'order'     => 'start ASC',
    ),
    ...

// Save call in Event model -------------
    $this->saveAll($data);

// $data ------------------------- 
'Event' => array(
    'id' => 'xxxxxxxx-65b4-4a75-ba4a-xxxxxxxxxxxx',
    'repeat_type' => '1',
    'repeat_interval' => '2',
    'repeat_weekdays' => 'ns',
    'repeat_on' => '1',
    'repeat_on_weekday' => '',
    'repeat_on_day' => '1',
    'repeat_end' => '',
    'timezone' => 'America/New_York',
    'times' => '',
    'modified' => '2013-11-02 01:07:27',
    'start' => '2013-11-03 01:36:00',
    'end' => '2013-11-10 05:36:00',
    'start_utc' => '2013-11-03 05:36:00',
    'end_utc' => '2013-11-10 10:36:00'
),
'EventInstance' => array(
    (int) 0 => array(
        'start' => '2013-11-05 01:11:00',
        'end' => '2013-11-05 05:36:00'
    ),
    (int) 1 => array(
        'start' => '2013-11-07 01:11:00',
        'end' => '2013-11-07 05:36:00'
    ),
    (int) 2 => array(
        'start' => '2013-11-09 01:11:00',
        'end' => '2013-11-09 05:36:00'
    ),
    (int) 3 => array(
        'start' => '2013-11-11 01:11:00',
        'end' => '2013-11-11 05:36:00'
    )
)
Foi útil?

Solução

Turns out, the trigger to save associated data when you call saveAll() has already passed by the time the beforeSave() adds the new associated data.

So - I just changed my beforeSave()s to beforeValidate()s, and it works.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top