[Zope] SQL methods in __init__

Garion jsuther1@twcny.rr.com
Wed, 19 Apr 2000 18:30:44 -0400


This solves it! Thanx alot.. My head no longer feels like imploding.

Evan Simpson wrote:
> 
> ----- Original Message -----
> From: "Garion" <jsuther1@twcny.rr.com>
> > I have a folder off my root folder that I'll call MyWebSite... In
> > MyWebSite, I have a MySQL Connection defined... When I add an instance
> > my new product, I want it to save various bits into tables off the MySQL
> > Connection, and use the LAST_INSERT_ID for the ID of the object..
> >
> > My problem seems to be when I try to do this in the __init__ of my
> > product, I haven't aquired the environment, and tells me that it can't
> > find MySQL Connection..
> 
> Right before the setObject call, you should have references to both the new
> object and the container into which you are about to put it.  You need to
> call a method on the object, in an acquisition context, which does the SQL
> setup, then put it in the container.  Here's the general pattern (untested):
> 
> obj = ThingClass()
> obj.__of__(container).install()
> container._setObject(obj.id, obj)
> 
> You provide 'install'.  The __of__ call is inherited from an acquisition
> class, and gives you an acquisition wrapper.
> 
> Cheers,
> 
> Evan @ 4-am & digicool
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )