CakePHP: Drawbacks with Indirectly Linked Models

I am having some problems using indirectly linked models in cakephp. My current model setup looks like this:

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

      

I am trying to store information about all these models inside ONE form. The disadvantages I am facing are as follows:

  • The form helper appears to be able to see the field type one level deep.

  • saveAll () only seems to be able to save the entries one level deep (for multiple model shapes).

I search everywhere for solutions to these problems, but since I'm new to CakePHP, I'm not sure what the newest techniques or "correct" methods are for solving these problems.

Any advice is greatly appreciated. Thanks everyone!

EDIT: I posted the code on my failed attempt: http://bin.cakephp.org/saved/58501

+2


a source to share


2 answers


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

I stumbled upon this limitation in the past and chose to work at the time by breaking my form into several smaller forms.



When using the saveAll and InnoDB tables, keep in mind that you are getting atomic transactions, as Cake will rollback if it fails to commit changes to the database.

So, while you can obviously work around this issue with a few lines of your own code (since Cake's saveAll one-liner falls short of expectations), you will have to spend more time if transactions are demanding.

0


a source


Hi I know this is an old post, but I thought I would post this to help others. As of CakePHP 2.1, you can save multiple levels of model association by using an option when calling saveAll (), more details here: http://book.cakephp.org/2.0/en/appendices/new-features-in-cakephp-2-1 .html # model-saveall-model-saveassociated-model-validateassociated

Example:



$this->MyModel->saveAll($this->request->data, array('deep'=>true));

      

As far as the FormHelper limitation is concerned, I'm at a loss as you are, I will probably resort to manually configuring input types since my fields don't need too much validation.

0


a source







All Articles