Changeset 324

Show
Ignore:
Timestamp:
04/29/08 17:42:06 (7 years ago)
Author:
ged
Message:

- use with_polymorphic mapper argument to implement polymorphic concrete

inheritance instead of the deprecated select_table. This bumps SA
requirement to 0.4.5 if you want to use concrete polymorphic inheritance.

- Also, issue a with_polymorphic argument for any Entity with children, which

allows loading polymorphically from the middle of a class chain (e.g,
loading all B and C in a A B C inheritance chain).

Files:
1 modified

Legend:

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

    r323 r324  
    415415 
    416416            if self.polymorphic: 
    417                 if self.children and not self.parent: 
     417                if self.children: 
    418418                    if self.inheritance == 'concrete': 
    419419                        keys = [(self.identity, self.entity.table)] 
    420420                        keys.extend([(child._descriptor.identity, child.table)  
    421421                                     for child in self._get_children()]) 
     422                        #XXX: we might need to change the alias name so that  
     423                        # children (which are parent themselves) don't end up 
     424                        # with the same alias than their parent? 
    422425                        pjoin = polymorphic_union( 
    423426                                    dict(keys), self.polymorphic, 'pjoin') 
    424                         kwargs['select_table'] = pjoin 
     427 
     428                        kwargs['with_polymorphic'] = ('*', pjoin) 
    425429                        kwargs['polymorphic_on'] = \ 
    426430                            getattr(pjoin.c, self.polymorphic) 
    427                     else: 
     431                    elif not self.parent: 
    428432                        kwargs['polymorphic_on'] = \ 
    429433                            self.get_column(self.polymorphic) 
     434 
    430435                    #TODO: this is an optimization, and it breaks the multi 
    431436                    # table polymorphic inheritance test with a relation.