I have solved these kinds of concerns with pyramid based applications using
sqlalchemy. However I need to look into the core of how Web2py handles
things to figure out the best way.

Sqlachemy allows you to put everything in:
1) Transactions
2) Sessions

So on submit you first create the parent record:
ad = Ad(....)
session.add(ad)
session.flush()

Now you have access to ad.id (parent id)

report = Report(...)
report.ad_id = ad.id
session.add(report)

Now if you used Sqlachemy relationships
ad.reports.append(report) # use this instead of report.ad_id = ad.id
session.flush()

Or in the case of having multiple children created before creating the
parent on a web form. You just submit all the form data at once and loop
through all reports.

ad = Ad(...)
session.add(ad)
session.flush()

get list of all reports in form submit
for report in reports:
  session.add(report)
  ad.reports.append(report)
session.flush()

If anything fails the transaction automatically roles everything back.

Or a easier solution is to only enable the children on edits. So you first
create the parent, then you can view/edit/delete children on the parent
edit page.

--
Regards,
Bruce

On Fri, Dec 23, 2011 at 10:00 AM, Cliff <cjk...@gmail.com> wrote:

> Bruce, you are more brave than me ;)
>
> I always like to get the parent record committed in the database
> before adding child records.
>
> that way you know the ID of the parent record and it has the minimal
> required fieldset safely saved away.  If there's a session
> interruption you don't have some potential orphan child records
> floating around somewhere.
>
> If you've solved those kinds of concerns, please share it with us.
>
> Thanks,
> Cliff Kachinske
>
> On Dec 23, 10:34 am, DenesL <denes1...@yahoo.ca> wrote:
> > On Dec 23, 10:11 am, Bruce Wade <bruce.w...@gmail.com> wrote:
> >
> > > Anyway which files should I start looking at to see how I can implement
> > > this functionality for myself and anyone else who wants it?
> >
> > Look for controller appadmin under your or any other app folder.
>



-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com

Reply via email to