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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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.