[Zope3-Users] Referencing objects

Thierry Florac thierry.florac at onf.fr
Fri Feb 4 11:04:33 EST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,


Le vendredi  4 février 2011,
  Michael Seifert <michael.seifert at gmx.net> a écrit :
======================================================================
> Hello everyone,
> 
> I recently started a Zope3 project, but I am stuck at the very
> beginning. Although I have some experience with Zope2, the more
> flexible approach to developing web applications was giving me a
> really hard start. Let me point out my situation:
> I created a container hierarchy which is stored in ZODB. Say I have a
> set of object types A, B, C, D, whose relationships look like the
> following (edges represent containment, i.e. A contains B,... where B
> and D are in subcontainers of A):
> 
>     A
>    / \
>   B   D
>   |
>   C
> 
> C has an attribute referencing an object of type D. As this attribute
> is mandatory on creation, I created a vocabulary, which ascends the
> hierarchy from the current context until it reaches A and returns all
> objects of type D.
> Now the part that doesn't work:
> While ascending from C to B and from B to A works fine, descending
> from A to D returns a security proxied object and since these objects
> cannot be pickled, I cannot store it's reference in the attribute of
> C.
> 
> 1. Is this the way it's meant to be done? :) What is your opinion of
> storing B and D objects in subcontainers of A?

That shouldn't be a problem, it's not different when you use a "basic"
folder-like container which, internally, stores sub-objects in an
internal b-tree container ; the only difference here is that you own
two internal containment attributes.


> 2. Are there any means to turn the vocabulary into trusted code, so it
> will not be encapsulated in a proxy (without deactivating the security
> proxy)?

Perhaps can you use the "removeSecurityProxy" function ?


> 3. How do you reference objects like you do with foreign keys in
> relational databases? I want to do this to prevent objects from being
> saved multiple times.

If the targetted object is persistent (and so a subclass of
"Persistent" class), it should be stored only once in the database
(just try to alter properties of an object and check if the other one
is also modified or not to check !)
Another way I commonly use to store references is to store only an
IIntIds utility reference, which is an integer ; the benefit of this
is that this value can easilly be indexed.

Regards,
Thierry
- -- 
Chef de projets intranet/internet
Office National des Forêts - Département Informatique
2, Avenue de Saint-Mandé
75570 Paris Cedex 12
Tél. : 01 40 19 59 64
Fax. : 01 40 19 58 85
Mél. : thierry.florac at onf.fr
Web. : http://www.onf.fr
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk1MI5EACgkQNl1a1Vtu7wrpzACeLPBWLaKoVVQn+fueivqnwhJb
jSwAn1LWhDCBnleB+jsfU/VoiJH0eBKD
=sWJB
-----END PGP SIGNATURE-----


More information about the Zope3-users mailing list