[Zope-dev] Is _getOb() best way to grab a ref to a
particular object?
Andrew Wilcox
circle@gwi.net
Mon, 22 Nov 1999 12:04:31 -0500
Right, what I'm looking for is to reference an absolute object, sort of
like saying "/usr/bin/sendmail" in the filesystem. The note about avoiding
an acquisition wrapper by using aq_base is helpful. Hmm, I don't know why
I thought I needed _getOb(). Some test I did that confused me because the
result was being rendered, and I didn't realize that was happening in the
publisher. I think.
Anyway, let's say I want to grab /topfolder/subfolder/myobj, and I know
they exist, so I'm not worried about acquisition along the way. So what
I've got now is:
obj = REQUEST.PARENTS[-1].topfolder.subfolder.myobj
or
na_obj = REQUEST.PARENTS[-1].topfolder.subfolder.myobj.aq_base
Ok, that's pretty straightforward!
Thanks!
Andrew
At 09:25 AM 11/22/99 -0500, Brian Lloyd wrote:
>> 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
>
>
>
>