-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The syntax is basically same. Look at the standard documentation and
examples for relation() and apply it to the decl layer.

- -aj

On 01.02.2009 16:17 Uhr, Eric Ongerth wrote:
> 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
> 

- -- 
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: i...@zopyx.com - Phone +49 - 7071 - 793376
Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535
Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkmFvewACgkQCJIWIbr9KYxuAwCeMzPu3fyzoba+Cwbws508398M
A9cAoJT/BDc77RQ3TDMC8ulBWCMp00kC
=lETo
-----END PGP SIGNATURE-----

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:i...@zopyx.com
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

Reply via email to