Changeset 432 for elixir/trunk/elixir
- Timestamp:
- 12/17/08 13:45:49 (3 years ago)
- Files:
-
- 1 modified
-
elixir/trunk/elixir/entity.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/elixir/entity.py
r428 r432 234 234 # they are added to the parent's table (whether the 235 235 # parent's table is already setup or not). 236 for col in self. columns:236 for col in self._columns: 237 237 self.parent._descriptor.add_column(col) 238 238 for constraint in self.constraints: … … 367 367 # sqlalchemy/test/orm/inheritance/concrete.py 368 368 # this should be added along other 369 kwargs = self.mapper_options369 kwargs = {} 370 370 if self.order_by: 371 371 kwargs['order_by'] = self.translate_order_by(self.order_by) … … 379 379 # non-polymorphic concrete doesn't need this 380 380 kwargs['inherits'] = self.parent.mapper 381 382 if self.inheritance == 'multi' and self.parent:383 col_pairs = zip(self.primary_keys,384 self.parent._descriptor.primary_keys)385 kwargs['inherit_condition'] = \386 and_(*[pc == c for c, pc in col_pairs])387 381 388 382 if self.polymorphic: … … 409 403 self.get_column(self.polymorphic) 410 404 411 #TODO: this is an optimization, and it breaks the multi412 # table polymorphic inheritance test with a relation.413 # So I turn it off for now. We might want to provide an414 # option to turn it on.415 # if self.inheritance == 'multi':416 # children = self._get_children()417 # join = self.entity.table418 # for child in children:419 # join = join.outerjoin(child.table)420 # kwargs['select_table'] = join421 422 405 if self.children or self.parent: 423 406 kwargs['polymorphic_identity'] = self.identity … … 425 408 if self.parent and self.inheritance == 'concrete': 426 409 kwargs['concrete'] = True 410 411 if self.parent and self.inheritance == 'single': 412 args = [] 413 else: 414 args = [self.entity.table] 415 416 # let user-defined kwargs override Elixir-generated ones, though that's 417 # not very usefull since most of them expect Column instances. 418 kwargs.update(self.mapper_options) 427 419 428 420 #TODO: document this! … … 431 423 kwargs['primary_key'] = [getattr(cols, colname) for 432 424 colname in kwargs['primary_key']] 433 434 if self.parent and self.inheritance == 'single':435 args = []436 else:437 args = [self.entity.table]438 425 439 426 # do the mapping … … 596 583 597 584 def columns(self): 598 #FIXME: this would be more correct but it breaks inheritance, so I'll 599 # use the old test for now. 600 # if self.entity.table: 601 if self.autoload: 585 if self.entity.table: 602 586 return self.entity.table.columns 603 587 else: … … 1089 1073 # query methods 1090 1074 def get_by(cls, *args, **kwargs): 1075 """ 1076 Returns the first instance of this class matching the given criteria. 1077 This is equivalent to: 1078 session.query(MyClass).filter_by(...).first() 1079 """ 1091 1080 return cls.query.filter_by(*args, **kwargs).first() 1092 1081 get_by = classmethod(get_by) 1093 1082 1094 1083 def get(cls, *args, **kwargs): 1084 """ 1085 Return the instance of this class based on the given identifier, 1086 or None if not found. This is equivalent to: 1087 session.query(MyClass).get(...) 1088 """ 1095 1089 return cls.query.get(*args, **kwargs) 1096 1090 get = classmethod(get)
