On Jan 9, 2009, at 7:42 PM, project2501 wrote:
>
> Hi,
> I'm trying to create a mapped class that allows parent/child
> relation of itself. I've spent the last 3 hours searching and reading
> the other posts on this, but can't get anything to work.
>
> I'm on 0.5rc4 and just want to declare this in a mapped class as such:
>
> class Conversion(Base):
> __tablename__ = 'conversion'
>
> id = Column(Integer, primary_key=True)
> name = Column(String(20))
>
> parent_id = Column(Integer, ForeignKey('conversion.id'))
> parent = relation("Conversion", backref="child")
>
> children = relation('Conversion', secondary=conversion_conversion,
> backref='parents')
>
> I was hoping to use the same style many-to-many declarations I do
> elsewhere. It creates fine, but doesn't work when adding objects.
The many-to-many is possible but is not really necessary for the
typical self-referential mapping. It depends on if you'd like a
single object to have many parents. However in your example above, it
appears you are creating two separate self-referring bidirectional
relationships, "parent/child" (which is also misconfigured, the many-
to-one side needs a remote_side argument) and "parents/children".
This would create two entirely isolated methods of associating one
Conversion object with another - there's no link between parent/child
and parents/children. Is this the desired effect ?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---