diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-08 03:16:38 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-08 03:16:38 +0000 |
| commit | b0ffcbc264f6a92ba5092e5d785a2dbfe418c307 (patch) | |
| tree | b36b7e879f166368e4c97d095a2ee9396e36c809 /lib/sqlalchemy | |
| parent | 8aa6a24fbb1244724906d613b6f9b3cb18751ee8 (diff) | |
| download | sqlalchemy-b0ffcbc264f6a92ba5092e5d785a2dbfe418c307.tar.gz | |
more fixup to self referential composite primary key mappings
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/properties.py | 10 |
1 files changed, 7 insertions, 3 deletions
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]): |
