Changeset 348

Show
Ignore:
Timestamp:
06/20/08 14:09:41 (5 years ago)
Author:
ged
Message:

First stab at making fields in base class work (see ticket #15).
Needs some cleanup.

Location:
elixir/trunk/elixir
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/elixir/entity.py

    r347 r348  
    77 
    88import sys 
     9import inspect 
    910import warnings 
     11from copy import copy 
    1012 
    1113import sqlalchemy 
     
    8486 
    8587        self.parent = None 
     88        #XXX: use entity.__subclasses__ ? 
    8689        self.children = [] 
    8790 
     
    99102        self._columns = list() 
    100103        self.constraints = list() 
     104 
    101105        # properties waiting for a mapper to exist 
    102106        self.properties = dict() 
     
    661665    return False 
    662666 
     667 
    663668class EntityMeta(type): 
    664669    """ 
     
    684689                                   if isinstance(attr, Property)] 
    685690        sorted_props = sorted(properties, key=lambda i: i[1]._counter) 
    686  
    687691        for name, prop in sorted_props: 
    688692            prop.attach(cls, name) 
     693 
     694        entity_base = None 
     695        for base in bases: 
     696            if isinstance(base, EntityMeta): 
     697                if not is_entity(base): 
     698                    entity_base = base 
     699        if entity_base: 
     700            # Process attributes (using the assignment syntax), looking for 
     701            # 'Property' instances and attaching them to this entity. 
     702            base_props = inspect.getmembers(entity_base, 
     703                                            lambda a: isinstance(a, Property)) 
     704            local_props = [(name, copy(attr)) for name, attr in base_props] 
     705            sorted_props = sorted(local_props, key=lambda i: i[1]._counter) 
     706            for name, prop in sorted_props: 
     707                prop.attach(cls, name) 
    689708 
    690709        # Process mutators. Needed before _install_autosetup_triggers so that 
  • elixir/trunk/elixir/properties.py

    r347 r348  
    116116        # delete the original attribute so that it doesn't interfere with 
    117117        # SQLAlchemy. 
    118         if hasattr(entity, name): 
     118        if name in entity.__dict__: 
    119119            delattr(entity, name) 
    120120