Re: saveAll with a hasMany relationship
This last message made me decide not to use saveall. So, I used saveall for each model since I have to indicate the name of model for me to save multiple record. - The best thing we can share in this world is knowledge Shared Corner -- View this message in context: http://cakephp.1045679.n5.nabble.com/saveAll-with-a-hasMany-relationship-tp1328838p4564408.html Sent from the CakePHP mailing list archive at Nabble.com. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: saveAll with a hasMany relationship
I think maybe the difference between what you and I was doing is that I was trying to save multiple main records at one time, whereas you were doing one. $this-data[1]['Recipe']['name'] = 'Delicious apple pie'; $this-data[1]['Recipe']['serves'] = 6; $this-data[1]['Recipe']['valid'] = 1; $this-data[1]['Tag'][0]['tag_id']=4; $this-data[1]['Tag'][1]['tag_id']=2; $this-data[1]['Tag'][2]['tag_id']=3; $this-data[1]['Recipe']['name'] = 'Pork spare ribs'; $this-data[1]['Recipe']['id'] = 166; $this-data[1]['Recipe']['serves'] = 4; $this-data[1]['Recipe']['valid'] = 1; $this-data[1]['Tag'][0]['tag_id']=1; $this-data[1]['Tag'][1]['tag_id']=5; $this-data[1]['Tag'][2]['tag_id']=9; - Once I added the hasMany ingredients that broke and I had to loop through the data and save each one individually: foreach ($this-data as $save) { $this-saveAll($save); } So $save would look like this: $save['Recipe']['name'] = 'Delicious apple pie'; $save['Recipe']['serves'] = 6; $save['Recipe']['valid'] = 1; $save['Tag'][0]['tag_id']=4; $save['Tag'][1]['tag_id']=2; $save['Tag'][2]['tag_id']=3; $save['Ingredient'][0]['name']='sugar'; $save['Ingredient'][1]['name']='apples'; and so on... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll with a hasMany relationship
Ok, just caught something in the cakephp online docs: saveAll(array $data = null, array $options = array()) Used to save (a) multiple individual records for a single model or (b) this record, as well as all associated records So perhaps this means I'm just trying to do something that isn't supported. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll with a hasMany relationship
Hi Nancy, I have a setup where I save the hasMany and HABTM in 1 go. It was a bit tricky and took me aswell, I think 3 weeks (shame) to finally get it sorted when I got the hint with the array setup. It really is all about having the $this-data set up in the right way. I suppose you have a form where your data comes from, how do your input fields are set up? What is the outcome of print_r($this-data)? Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll with a hasMany relationship
Yeah, this is essentially what I had to end up doing. I wanted to save a bunch of records at once and it worked great until I added the hasOne/hasMany relationship. So I had to stop saving them all at once and do one at a time. But at least it saves the associated data at the same time as it does the main data. I wish that I could figure out a way to save ALL the data at once, rather than one row (and associated rows) at a time. It just seems like the way I ended up doing it is rather cheesy. On Aug 21, 2:22 am, Luke eike...@gmail.com wrote: Hi Nancy, I had the same issue like you are describing, how to save the hasMany after positing it on here, I found the solution. I have a recipe hasMany Ingredient relationship, the importance is to have the array formated in the right way. It needs to look like below, than it will work. [Recipe] = Array ( [recipe_name] = Champions [Rezeptportion] = 2 ) [Ingredient] = Array ( [0] = Array ( [ingredientname] = Champions ) [1] = Array ( [ingredientname] = pepper ) Try this out and let me know if you struggle, maybe we find an answer. Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll with a hasMany relationship
Here's the structure I ended up having to go with $save['Constoptvalue']['device_id'] = 16; $save['Constoptvalue']['constopt_id'] = 1; $save['Constoptvalue']['valid'] = 1; $save['Compoundchainlist']['name'] = 'poohbear'; $save['Layer'][0]['layer_id']=4; $save['Layer'][1]['layer_id']=2; $save['Layer'][2]['layer_id']=3; So I can only save one 'Constoptvalue' with it's related data at once, rather than everything that was modified (multiple rows). *sad face* On Aug 21, 2:22 am, Luke eike...@gmail.com wrote: Hi Nancy, I had the same issue like you are describing, how to save the hasMany after positing it on here, I found the solution. I have a recipe hasMany Ingredient relationship, the importance is to have the array formated in the right way. It needs to look like below, than it will work. [Recipe] = Array ( [recipe_name] = Champions [Rezeptportion] = 2 ) [Ingredient] = Array ( [0] = Array ( [ingredientname] = Champions ) [1] = Array ( [ingredientname] = pepper ) Try this out and let me know if you struggle, maybe we find an answer. Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll with a hasMany relationship
Hi Nancy, I had the same issue like you are describing, how to save the hasMany after positing it on here, I found the solution. I have a recipe hasMany Ingredient relationship, the importance is to have the array formated in the right way. It needs to look like below, than it will work. [Recipe] = Array ( [recipe_name] = Champions [Rezeptportion] = 2 ) [Ingredient] = Array ( [0] = Array ( [ingredientname] = Champions ) [1] = Array ( [ingredientname] = pepper ) Try this out and let me know if you struggle, maybe we find an answer. Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
saveAll with a hasMany relationship
I was so happy. I finally figured out how to make saveAll work with my HABTM relationship so I figured adding a hasMany would be a piece of cake. I have a little practice data structure set up to test it out. $save[1]['Constoptvalue']['device_id'] = 16; $save[1]['Constoptvalue']['constopt_id'] = 1; $save[1]['Constoptvalue']['valid'] = 1; $save[1]['Layer'][0]['layer_id']=4; $save[1]['Layer'][1]['layer_id']=2; $save[1]['Layer'][2]['layer_id']=3; This works brilliantly. So then I add in my hasMany data: $save[1]['Cotest'][0]['symbol']='buggers'; And do my saveall: $this-Constoptvalue-saveAll($save); Everything works, except Cotest. I can tell the relationship is defined well, I get the proper data when I read my Constoptvalue structure. Any ideas? Darn, I thought I had this nailed finally. Thanks all. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: saveAll with a hasMany relationship
I just wanted to add, I'm saving multiple records at a time. So $this- data might have an index going up to 5 or so with models for 3 or more different things. I did manage to get a hasMany to work, but not with multiple records. $save['Firstname']['firstname']='Margarie'; $save['Nickname'][0]['nickname'] = 'Margy'; $this-Firstname-saveAll($save); That worked, but what if I want to save 3 different firstname/nickname pairs at a time? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---