Search code examples
phpcakephpcakephp-1.3has-manysave

How should data be formatted in CakePHP to save three levels of associations with saveAll()?


I'm trying to build an "Add an Event" page. You can add multiple "Schedules" - each of which will have calculations run on the date(s) / repeat options you set to create "Dates".

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

The question is - how does the data need to be formatted and/or how to the field names need to read in order to be able to saveAll() the data so Date(s) are also saved. I have it currently working so it saves the Event and the Schedule... but I can't get it to also save the Date(s).


Solution

  • Actually, since CakePHP 2.1, you can do it with saveAll(). Doesn't matter the deep level you have within your models. Here you can see the new features.

    http://book.cakephp.org/2.0/en/appendices/new-features-in-cakephp-2-1.html#model-saveall-model-saveassociated-model-validateassociated