Changeset 284 for elixir/trunk/elixir/entity.py
- Timestamp:
- 12/17/07 12:22:12 (5 years ago)
- Files:
-
- 1 modified
-
elixir/trunk/elixir/entity.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/elixir/entity.py
r279 r284 82 82 self.builders = [] 83 83 84 self.is_base = is_base(entity) 84 85 self.parent = None 85 86 self.children = [] 86 87 87 88 for base in entity.__bases__: 88 if isinstance(base, EntityMeta) and not base.__bases__[0] is object:89 if isinstance(base, EntityMeta) and not is_base(base): 89 90 if self.parent: 90 91 raise Exception('%s entity inherits from several entities,' … … 252 253 self.parent._descriptor.add_constraint(constraint) 253 254 return 254 elif self.inheritance == 'concrete': 255 elif self.inheritance == 'concrete': 256 #TODO: we should also copy columns from the parent table if the 257 # parent is a base entity (whatever the inheritance type -> elif 258 # will need to be changed) 255 259 # copy all columns from parent table 256 260 for col in self.parent._descriptor.columns: … … 438 442 check_duplicate = not self.allowcoloverride 439 443 440 if check_duplicate and self.get_column(col.key ) is not None:444 if check_duplicate and self.get_column(col.key, False) is not None: 441 445 raise Exception("Column '%s' already exist in '%s' ! " % 442 446 (col.key, self.entity.__name__)) … … 481 485 self.mapper_options['extension'] = extensions 482 486 483 def get_column(self, key ):487 def get_column(self, key, check_missing=True): 484 488 "need to support both the case where the table is already setup or not" 485 489 #TODO: support SA table/autoloaded entity … … 487 491 if col.key == key: 488 492 return col 493 if check_missing: 494 raise Exception("No column named '%s' found in the table of the " 495 "'%s' entity!" % (key, self.entity.__name__)) 489 496 return None 490 497 … … 531 538 return self.entity.table.columns 532 539 else: 540 #FIXME: depending on the type of inheritance, we should also 541 # return the parent entity's columns (for example for order_by 542 # using a column defined in the parent. 533 543 return self._columns 534 544 columns = property(columns) … … 581 591 return getattr(owner, self.attrname) 582 592 593 def is_base(cls): 594 """ 595 Scan bases classes to see if any is an instance of EntityMeta. If we 596 don't find any, it means the current entity is a base class (like 597 the 'Entity' class). 598 """ 599 for base in cls.__bases__: 600 if isinstance(base, EntityMeta): 601 return False 602 return True 583 603 584 604 class EntityMeta(type): 585 605 """ 586 606 Entity meta class. 587 You should only use this if you want to define your own base class for your588 entities (ie you don't want to use the provided 'Entity' class).607 You should only use it directly if you want to define your own base class 608 for your entities (ie you don't want to use the provided 'Entity' class). 589 609 """ 590 610 _entities = {} 591 611 592 612 def __init__(cls, name, bases, dict_): 593 # only process subclasses of Entity, not Entity itself 594 if bases[0] is object: 613 # Only process further subclasses of the base classes (Entity et al.), 614 # not the base classes themselves. We don't want the base entities to 615 # be registered in an entity collection, nor to have a table name and 616 # so on. 617 if is_base(cls): 595 618 return 596 619 … … 621 644 prop.attach(cls, name) 622 645 623 # process mutators. Needed before setup_proxy for metadata 646 # Process mutators. Needed before _install_autosetup_triggers so that 647 # we know of the metadata 624 648 process_mutators(cls) 625 649 … … 710 734 '''Setup all entities in the list passed as argument''' 711 735 712 for entity in e lixir.entities:736 for entity in entities: 713 737 if entity._descriptor.autosetup: 714 738 _cleanup_autosetup_triggers(entity) … … 783 807 ''' 784 808 __metaclass__ = EntityMeta 785 809 786 810 def __init__(self, **kwargs): 787 811 for key, value in kwargs.items():
