On Jul 23, 2006, at 4:12 AM, Darryl Cousins wrote:
Gary Poster wrote:
If the relationship is intrinsic to one object's data model but not
to the other's, then it makes sense to have a Python pointer on the
first object.
Hi Gary,
Am I right that 'a Python pointer on the first object' is defined by
simply defining the schema field, eg::
mypointer = Object(
title="Pointer to object",
schema=IInterfaceOfTheTarget)
Then everything else will fall into place. I could even use formlib to
edit the object being pointed to from within a form editing the 'first
object'.
The second object would not even know it is pointed to. For it to
know I
would need to use a relationship as you go on to discuss.
Have a correctly understood?
Yes, precisely; and for what it is worth, the Object schema value
lets formlib work, and specifies part of your software's "contract",
but is not necessary for the most basic story. The simplest clear
case (Where `app` represents some ZODB folder, like the application
root):
class DemoSubject(persistent.Persistent):
pass
class DemoObject(persistent.Persistent):
pass
app['demo'] = DemoSubject()
app['demo'].mypointer = DemoObject()
By the way, a small but possibly important subtlety about the object
widgets that are associated with the schema object fields is that
(unless you manage your form pretty carefully) they change value by
creating new instances of the sub-object and replacing it on the main
object, not by modifying an old sub-object instance, IIRC.
Sometimes Choice fields with a custom vocabulary or source are what
you want, if you want to make a pointer to an object that already
exists somewhere in the database.
Gary
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users