Tuesday 15 January 2013

cakephp saving data for a related model's related model (not typo) -


I have participated in a small amount of problem in saving the data in cake php. Many

  • / Strong> group

    I am in a view to create a new district, in which I have given the user permission to create several new departments. When creating each department, the user can create several groups for that department. Now trouble I am unsure about how to save group data.

    For each department that has been built on the fly, using a number of index methods for input (i.e. "Department .0.name", department 2.0.type) Save using all the methods, however, for each group that is created, I will need a department_ID because the departments of any district have not been saved yet, they do not have an ID. How can I save the data of this new district, save new departments, and maintain new groups associated with it? Is there any way that I can address the name attributes of group entrepreneurs who will create the appropriate association, such as "Department .0.Group Group.name", for example?

    Thanks in advance thanks! !! If nothing is unclear, please do not hesitate to say, I will be happy to refresh again.

    What does your postal data look like?

      & lt; ? Php debug ($ this-> data); ? & Gt;   

    If it is not in the correct format, then the respective models will not be saved. Cake knows that to catch the "last look (") of the model that have not yet been saved, So you do not have to worry about those people ... what I'm not sure about, and docs do not really go away, how deeply it remains. The examples given are as follows:

      $ this-> Data = Array ([article] = & gt; Hey ([title] => my first article) [comment] => Array ([0] => Array ([comment] => Comment 1 [user_id] = & gt; 1) [1] => Hey ([comment] => comment2 [user_id] => 2))) $ this-> Paragraph-> Saving all ($ this-> data);   

    This is the correct structure (CakePip 1.3) to save the associated model of 'Hamman' relationship, but I'm not sure it goes for any child with any depth.

    One thing that comes to my mind is to create an array according to the format above, but leave the original model manually by saving the original model data, get :: getLastInsertId ();


    [ UPDATE ] I have just tested your theory and it will work according to your wishes.

        

    will be generated:

      & lt; Input name = "data [section] [0] [group] [0] [name]" type = "text" id = "department0Group0name" & gt;   

    [ UPDATE 2 ] I searched some things in ob / cake / model / model.fpp and found:

     < Code> & lt ;? Php ... associated with saving public function ($ data = zero, $ option = array ()) {... ... // code left ... if ($ option ['deep']) {/ / This all organizations $ save = $ this- & gt; {$ Association} - & gt; Save associate ($ value, array_merge ($ option, array 'atomic' = & gt; wrong))); } ... ... ... // Quit the code ...? & Gt;    

  • No comments:

    Post a Comment