Ticket #16: constraint_name.patch

File constraint_name.patch, 1.3 kB (added by guest, 6 years ago)

Patch allowing overriding of foreign key identifiers

  • elixir/relationships.py

     
    572572                # several belongs_to relations between two objects 
    573573                self.primaryjoin_clauses.append(col == pk_col) 
    574574             
    575             # In some databases (at lease MySQL) the constraint name needs to  
    576             # be unique for the whole database, instead of per table. 
    577             fk_name = "%s_%s_fk" % (source_desc.tablename,  
    578                                     '_'.join(fk_colnames)) 
     575            if 'name' not in self.constraint_kwargs: 
     576                # In some databases (at lease MySQL) the constraint name needs to  
     577                # be unique for the whole database, instead of per table. 
     578                fk_name = "%s_%s_fk" % (source_desc.tablename,  
     579                                        '_'.join(fk_colnames)) 
     580                self.constraint_kwargs['name'] = fk_name 
     581                 
    579582            source_desc.add_constraint( 
    580                 ForeignKeyConstraint(fk_colnames, fk_refcols, name=fk_name, 
     583                ForeignKeyConstraint(fk_colnames, fk_refcols, 
    581584                                     **self.constraint_kwargs)) 
    582585 
    583586    def get_prop_kwargs(self):