Hi,
Thanks for the response. I'm still fairly new to SA but am very
impressed with this package!
I tried a variety of combinations of mappings. If I use just the
parent_id,parent it would seem to make sense logically if my children
only have one parent.
The tables generate fine. But when I try to set the parent of a child at
runtime it throws an exception about Conversion not being a list or
collection or something. So I was experimenting with the M2M, and as you
see, its not right.
Logically, the self referring parent should be enough I would think. Is
there another way using Base without having to use another mapping
technique since all my other classes are Base derived?
Thank you.
On Fri, 2009-01-09 at 20:17 -0500, Michael Bayer wrote:
>
> 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
-~----------~----~----~----~------~----~------~--~---