In the Cake cookbook, all the examples seem to use save()/saveAll() to update HABTM relationships for a single record at a time. However, I’d like to create many to many associations using a single call. For example, I have 3 concert events, and I have 2 flyers. And I want those 2 flyers to be associated with each of the concert events.
I have 2 tables, events, flyers and a join table: events_flyers. So I suppose I could just add the records to the join table manually. But I was wondering if there was some way I could do something similar to:
$this->Event->updateAll(
$flyers,
array('festival_id' => $id)
)
Or does updateAll() only work on regular fields?
This answer doesn’t use
updateAll, but I know that you can create HABTM associations usingsaveand specially keyed data in$this->data:So using this, could you take it a step further and use
saveAllalong with multiple Event records? For example:Does that work for you?