views:

114

answers:

1

I'm having some issues with dealing with indirectly associated models in cakephp. My current model setup is as follows:

Deliveries hasOne License
License belongsTo Delivery
License hasAndBelongsToMany Product (and vice-versa)
License hasAndBelongsToMany ProductOption (and vice-versa)

I'm trying to save information about ALL of these models inside ONE form. The shortcomings I'm running into are the following:

  1. The form helper only seems able to see the field type one level deep.

  2. saveAll() only seems able to save records one level deep (for multiple model forms).

I'm searching everywhere for the solutions to these issues, but since I'm new to CakePHP, I'm not sure what the newest methods or "correct" methods are for dealing with these issues.

Any advice is much appreciated. Thank you all!

EDIT: I've posted code to my failed attempt here: http://bin.cakephp.org/saved/58501

A: 

saveAll() only seems able to save records one level deep (for multiple model forms).

I have stumbled across this limitation in the past and chose, at the time, to work around it by breaking up my form into multiple smaller forms.

One thing to bear in mind when using saveAll and InnoDB tables is that you get atomic transactions, as Cake will perform a rollback if it is unable to commit changes to the database.

So, while you can obviously work around the issue with a few lines of your own code (since Cake's saveAll one-liner doesn't live up to expectations), you would have to spend more time if transactions were a requirement.

deizel