From b0ffcbc264f6a92ba5092e5d785a2dbfe418c307 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 8 Oct 2006 03:16:38 +0000 Subject: more fixup to self referential composite primary key mappings --- lib/sqlalchemy/orm/properties.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 2ad2c2b8c..11c612467 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -207,10 +207,14 @@ class PropertyLoader(StrategizedProperty): if self.secondaryjoin is not None: return sync.MANYTOMANY elif self._is_self_referential(): - if list(self.foreignkey)[0].primary_key: - return sync.MANYTOONE + # for a self referential mapper, if the "foreignkey" is a single or composite primary key, + # then we are "many to one", since the remote site of the relationship identifies a singular entity. + # otherwise we are "one to many". + for f in self.foreignkey: + if not f.primary_key: + return sync.ONETOMANY else: - return sync.ONETOMANY + return sync.MANYTOONE elif len([c for c in self.foreignkey if self.mapper.unjoined_table.corresponding_column(c, False) is not None]): return sync.ONETOMANY elif len([c for c in self.foreignkey if self.parent.unjoined_table.corresponding_column(c, False) is not None]): -- cgit v1.2.1