質問

Description / Explanation:

On the "Add an Event" page, you can add multiple Schedules. When you saveAll(), it saves the Event data and all the Schedule(s) data - this is working correctly.

But THEN, I want to process the schedule(s) data and build individual rows in the "dates" table.

Event hasMany Schedule
Schedule belongsTo Event
Schedule hasMany Date
Date belongsTo Schedule

So - I'm loading the Date model, and repeating through each Schedule that was passed, and processing/inserting the dates (based on repeat, start date...etc etc).

My problem / Question:

I need the id of each schedule for it's Dates ("schedule_id" field). How do I get the id's of individual Schedules during the repeat? Currently, I'm doing this:

foreach($this->data['Schedule'] as $i => $value) {
    $this->data['Date']['schedule_id'] = $this->Event->Schedule->id;
    //other stuff here
    $this->Date->saveAll($this->data['Date']);
}

But that gives me the same id in every loop.

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top