Say I want to have a one-to-many auto-referential relationship.  I
thought from reading a previous post on a one-to-one auto-referential
relationship, that I could do something like this:

class Person(Entity):
    name = Field(Text)
    children = OneToMany('Person')
    mother = OneToOne('Person')

    def __repr__(self):
        return '<Person %s>' % (self.name)

...
and then, ...

mom = Person(name='Mom')
baby1 = Person(name='Baby1')
baby2 = Person(name='Baby2')
baby1.mother = mom
baby2.mother = mom
print baby1.mother
print mom.children

which gives me:
<Person Mom>
Traceback (most recent call last):
  File "./testmodel.py", line 22, in <module>
    print mom.children
AttributeError: 'Person' object has no attribute 'children'

Is there a way to set this up so that a Person can have many children,
and a child only one mother?

Thanks,

Mike




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to