this is because the initial reference to SelfRef() is lost
immediately, and the reference the instrumented list for "children"
holds to its parent is a weak reference, which is intended to avoid
delayed gc collection issues.
defining SelfRef as this, for example, fixes it:
l = []
class SelfRef(object):
def __init__(self):
l.append(self)
append() has no return value so the two code snippets are not
equivalent - sr1 would be None in the second case.
i.e.:
assert [].append(5) is None
On Apr 4, 2007, at 4:36 AM, ml wrote:
> selfref=Table("selfref", metadata,
> Column("id",Integer, primary_key=True),
> Column("id_par",Integer, ForeignKey("selfref.id"))
> )
>
> class SelfRef(object):pass
>
> mapper(SelfRef, selfref, properties={
> "children":relation(SelfRef, cascade="all")
> })
>
> Following construction is fine:
>
> sr1 = SelfRef()
> sr1.children.append(SelfRef())
>
> but
>
> sr1 = SelfRef().children.append(SelfRef())
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---