Changeset 6
- Timestamp:
- 01/26/07 18:19:10 (6 years ago)
- Location:
- supermodel/trunk/supermodel
- Files:
-
- 1 added
- 1 modified
-
relationships.py (modified) (8 diffs)
-
tests/test_multi.py (added)
Legend:
- Unmodified
- Added
- Removed
-
supermodel/trunk/supermodel/relationships.py
r5 r6 159 159 160 160 self.foreign_key = [] 161 self.primaryjoin_clauses = list() 162 161 163 for key in target_desc.primary_keys: 162 keycol = key.column163 refcol = target_desc.tablename + '.' + keycol.name164 pk_col = key.column 165 refcol = target_desc.tablename + '.' + pk_col.name 164 166 #CHECKME: why do we use a Field here instead of directly using a 165 167 # Column 166 field = Field( keycol.type, colname=self.name + '_' + keycol.name,168 field = Field(pk_col.type, colname=self.name + '_' + pk_col.name, 167 169 index=True) 168 170 … … 171 173 columns.append(field.column.name) 172 174 source_desc.add_field(field) 175 176 # build up the primary join. This is needed when you have several 177 # belongs_to relations between two objects 178 self.primaryjoin_clauses.append(field.column == pk_col) 173 179 174 180 # TODO: better constraint-naming? … … 184 190 cols = [k.column for k in self.target._descriptor.primary_keys] 185 191 kwargs['remote_side'] = cols 192 193 kwargs['primaryjoin'] = and_(*self.primaryjoin_clauses) 186 194 187 195 #CHECKME: is this of any use? … … 211 219 for f in self.inverse.foreign_key] 212 220 221 kwargs['primaryjoin'] = and_(*self.inverse.primaryjoin_clauses) 213 222 #CHECKME: is this of any use? 214 223 # kwargs['backref'] = self.inverse.name … … 230 239 if self.inverse.secondary: 231 240 self.secondary = self.inverse.secondary 241 self.primaryjoin_clauses = self.inverse.secondaryjoin_clauses 242 self.secondaryjoin_clauses = self.inverse.primaryjoin_clauses 232 243 233 244 if not self.secondary: … … 242 253 # case. I think it's also usefull when you have several many-to-many 243 254 # relations between the same objects. I'll have to test that... 255 # no it's not since the tables are different. It would only if the 256 # tables where the same, but I'm not sure if it has some sense to be 257 # in that situation. 244 258 # if self.entity is self.target: 245 259 # print "many2many self ref detected" 246 self.primary _clauses = list()247 self.secondary _clauses = list()260 self.primaryjoin_clauses = list() 261 self.secondaryjoin_clauses = list() 248 262 249 263 for desc, join_name in ((e1_desc, 'primary'), … … 279 293 280 294 # build join clauses 281 getattr(self, join_name+'_clauses').append(col == pk_col) 295 join_list = getattr(self, join_name+'join_clauses') 296 join_list.append(col == pk_col) 282 297 283 298 # TODO: better constraint-naming? … … 306 321 kwargs = self.kwargs 307 322 308 if self. entity is self.target:309 kwargs['primaryjoin'] = and_(*self.primary _clauses)310 kwargs['secondaryjoin'] = and_(*self.secondary _clauses)323 if self.target is self.entity: 324 kwargs['primaryjoin'] = and_(*self.primaryjoin_clauses) 325 kwargs['secondaryjoin'] = and_(*self.secondaryjoin_clauses) 311 326 312 327 m = self.entity.mapper
