I am using Catalyst Perl MVC framework with HTML::FormHandler as forms processor.
Are there any ways to create multiple objects and save them into appropriate separate tables using single form?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
After some time was spent reading the documentation and finally IRC help I figured out how to do it. It’s quite simple.
Let’s say we have 2 related tables: ‘account’ and ‘user’. And ‘account’ hasMany ‘users’, with this relationship being called ‘users’.
The code in controller Account.pm stays the same (remember we are using HTML::FormHandler to process the form and create new objects):
All we do is use http://metacpan.org/pod/HTML::FormHandler::Field::Repeatable like that in our lib/MyApp/Form/Account.pm:
After submitting we get freshly created ‘account’ and ‘user’ objects, where ‘user’ already has corresponding ‘account_id’ inserted 🙂