Mastro, James wrote:
> I have been using ReferenceField's in my Archetype classes a lot lately. As
> I understand it (and I'm hoping that someone will tell me I'm wrong), one
> can *not* simply write:
>
> value = object.getMyReferenceFieldName()
this should work. if you are using a multi-valued reference field, then this
will return a list of referenced objects (or possibly a tuple, i forget), but
i think if it's a single valued field, then the referenced object, if any,
should be what is returned. have you tried it?
> So, when I want to access *only* the first reference (which is most of the
> time because rarely do I store a list in such field), I do something like
> the following:
this shouldn't be necessary, but it would work. well, with a couple of notes:
> def getFirstReference(object=None, reference=None):
i'm guessing that the second argument should be 'relationship' and not
'reference'.
> return_object = None
> if object and relationship:
> references = object.getReferences(relationship)
> if references:
> if references[0]:
these nested ifs seem unnecessary. if there aren't any references, then your
first if would fail. if you have any references, then 'references[0]' should
exist, so the second check is superfluous. in fact, it could cause
problems... empty containers, for instance, evaluate to False, so if you were
referencing a folder and it didn't contain any objects, you might get
unexpected behaviour.
> return_object = references[0]
>
> return return_object
>
> This seems a bit excessive to me. Is there an easier/faster way to make
> such access?
it is a bit excessive, and, as mentioned above, it's unnecessary. the
accessor idiom should work fine.
-r
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642_______________________________________________
Plone-Users mailing list
Plone-Users@...
https://lists.sourceforge.net/lists/listinfo/plone-users