Changeset 534 for elixir

Show
Ignore:
Timestamp:
01/29/11 20:53:10 (16 months ago)
Author:
ged
Message:

- Fixed bad foreign key constraint generated for classes inheriting from a

class with multiple primary keys when using the "multi" inheritance.
Patch from & closes #114.

Location:
elixir/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r528 r534  
    1212Bug fixes: 
    1313- Fixed a few tests to work on SA 0.6.x 
     14- Fixed bad foreign key constraint generated for classes inheriting from a 
     15  class with multiple primary keys when using the "multi" inheritance. 
     16  Patch from & closes #114. 
    1417 
    15180.7.1 - 2009-11-16 
  • elixir/trunk/elixir/entity.py

    r532 r534  
    199199                    tablename = parent_desc.table_fullname 
    200200                    join_clauses = [] 
     201                    fk_columns = [] 
    201202                    for pk_col in parent_desc.primary_keys: 
    202203                        colname = options.MULTIINHERITANCECOL_NAMEFORMAT % \ 
     
    208209                        # attached to a table 
    209210                        pk_col_name = "%s.%s" % (tablename, pk_col.key) 
    210                         fk = ForeignKey(pk_col_name, ondelete='cascade') 
    211                         col = Column(colname, pk_col.type, fk, 
    212                                      primary_key=True) 
     211                        col = Column(colname, pk_col.type, primary_key=True) 
     212                        fk_columns.append(col) 
    213213                        self.add_column(col) 
    214214                        join_clauses.append(col == pk_col) 
    215215                    self.join_condition = and_(*join_clauses) 
     216                    self.add_constraint( 
     217                        ForeignKeyConstraint(fk_columns, 
     218                            parent_desc.primary_keys, ondelete='CASCADE')) 
    216219                elif self.inheritance == 'concrete': 
    217220                    # Copy primary key columns from the parent. 
  • elixir/trunk/tests/test_inherit.py

    r490 r534  
    88def setup(): 
    99    metadata.bind = 'sqlite://' 
    10 #    metadata.bind = 'postgres://@/test' 
     10#    metadata.bind = 'postgresql://@/test' 
    1111#    metadata.bind.echo = True 
    1212    elixir.options_defaults['shortnames'] = True 
     
    144144        setup_all() 
    145145 
     146    def test_multi_pk(self): 
     147        class A(Entity): 
     148            using_options(inheritance='multi') 
     149            firstname = Field(String(50), primary_key=True) 
     150            lastname = Field(String(50), primary_key=True) 
     151 
     152        class B(A): 
     153            using_options(inheritance='multi') 
     154 
     155        setup_all(True) 
     156 
     157        b1 = B(firstname='1', lastname='b') 
     158        b2 = B(firstname='2', lastname='b') 
     159 
     160        session.commit() 
     161 
     162        b1.delete() 
     163 
     164        session.commit() 
     165 
     166        assert len(B.query.all()) == 1 
     167 
    146168    def test_multitable_polymorphic_load(self): 
    147169        class A(Entity):