Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

How to save multiple Items at once? 14 Nov 2012 14:41 #5352

Hi,

Simply said: How to save multiple Items at once?

Here is my question:

I'm looking for a way to do this with Cook.

Any suggestions?

Regards,

GC

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 14:53 #5353

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Hi @goslingcools,

Simply put, this is not a simple task. How familiar are you with ajax?

The best way would be to have 2 forms: 1 - CV, 2 - Training (Single items);

Using ajax, load the training form into the CV form with multiple instances (as many as you want with an 'add more training' button maybe. Adapt the save routine to capture the training instances of the form in an array and loop through them passing them to the save function of training with the CV id (whatever the name of the foreign key you've implemented is) upon successful save of the CV.

Naturally, the prepareQuery() will need to get the related training info too when launching an edit/update on a CV.

Check out this tutorial that @admin provided about implementing AJAX in joomla/cook: www.j-cook.pro/forum/7-design-your-appli...sing-the-modelactrlr

hope it helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 15:06 #5354

I was thinking of using AJAX too :-)

But I would need 3 tables right?

1) CV's
2) Trainings
3) Table that links multiple Training ID's to a single CV ID

Right?

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 15:08 #5355

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Not necessarily,

Just a cv_id in the trainings ;)

G
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 15:09 #5356

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Of course, you'll have this id available from the save routine of the CV item, ready to pass as FKey on success, right?
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 15:12 #5357

Ok, that's much better. And less work, thanks!

I was thinking way to complex. :-)

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 15:14 #5358

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
It really depends how complex the entity is - i.e. how many fields it has but, it seems trainings are small objects. It's only worth breaking them out into more tables if a lot of the values in fields will be re-used over and over to reduce redundancy/duplication.

Glad it helped!

G
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The following user(s) said Thank You: goslingcools

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 15:19 #5359

This CV thing was just an example. Did not know how to explain it otherwise... :-)

But yes, my subitems will be quite simple.

Thanks again!

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 14 Nov 2012 16:10 #5360

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
2 tables fine for that then...

Best of luck!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 21 Nov 2012 08:56 #5543

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
All you have to do is not necessary with AJAX. In facts, it is not the best.

Ajax is good when you want to add some entries in your 'training' list.
So, I think you can implement AJAX for that, but to save the whole at one time, it is not good.

Fistly, for Ajax you need first that your main item (CV) is already initialized (id value)
Then, when you submit the form, if the id is not yet initialized, you will need anyway to send your complete form (main + N:1)


TODO :
1. Send the complete form.
2. Decrypt all this in the save() method of your controller. The controller have to work with the 2 models.

Controller :
- Save or update the main item, then get the ID of this saved object.
$modelCv->getState('cv.id');
- If save() was successfull, you can now add the individual 'training' entries, using a second model for that.

Very important : In the model in wich you will write a little bit, you must check carefully if you are dealing with new or existing items.
Read them all associated to this CV, then merge with the current posted form training entries.
(add, update, delete) You must do all this manually.

Not sure to be clear.
Can you understand the concept in main lines ?
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

Re: How to save multiple Items at once? 21 Nov 2012 09:02 #5545

Thanks for your answer!

I solved it with some custom code. No ajax used.
But I think it's much to customized now to paste it here. :-) For example I did not use the model for saving etc of the trainings etc.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.075 seconds
In the begining i would like to say that j-cook is absolutly fantastic tool! And the person who created it is a genius.
Czyżak (Forum)  

Get Started