Kevin, the default behavior is for relations to be represented by lists. If what you want is a tree structure where a directory can only have a single parent, you would use backref=backref("parentdir", uselist=False). Or at least that's how you'd do it in plain SA; i haven't used the declarative base yet so I don't know if there's a different syntax.
On Feb 1, 6:35 am, Kevin Dangoor <dang...@gmail.com> wrote: > I've done many many-to-one relationships with SQLAlchemy, but there > must be something obvious I'm doing wrong here: > > class Directory(Base): > __tablename__ = "directories" > > id = Column(Integer, primary_key=True) > name = Column(String, unique=True) > subdirs = relation('Directory', backref="parentdir") > parent_id = Column(Integer, ForeignKey('directories.id')) > > def __str__(self): > return "Dir: %s" % (self.name) > > "Base" is standard declarative Base. > > The odd behavior that I'm seeing is that on a newly created Directory > instance, both subdirs and parentdir are lists when I would expect > parentdir to just be null or a Directory. > > This is using SQLAlchemy 0.5.2. > > I do hope there's something obvious that I missed... > > Thanks, > Kevin > > -- > Kevin Dangoor > > email: k...@blazingthings.com > blog:http://www.BlueSkyOnMars.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---