RE: [Zope-dev] Is _getOb() best way to grab a ref to a particular object?
I need to grab a reference to a particular object in the ZODB from an external method, bypassing acquisition. Is this the right way to do it:
def test(self, REQUEST=None): """doc string""" myobj = REQUEST.PARENTS[-1].aTopLevelFolder.anotherFolder._getOb('id_o f_myobj') ...do stuff with myobj: myobj.title, myobj.index_html, myobj.property = 123 ...
Maybe, maybe not... _getOb will not return an acquired object, but if the object exists it _will_ be returned as a "wrapped" object so acquisition will be preserved in the result. I'm not clear from your example whether this is what you want. If you want the *resulting* object to be non-acquiring, you'll want to do something like: def test(self, REQUEST=None): """ """ # get object named 'foo' from self, but dont allow it # to be found via acquisition. obj=self._getOb('foo') # while we know that foo is not acquired from above, it # is still wrapped in the context of 'self', so to disable # acquisition we need to unwrap it. non_aquiring_obj=obj.aq_base ... Hope this helps! Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
participants (1)
-
Brian Lloyd