Changeset 345

Show
Ignore:
Timestamp:
06/19/08 12:35:49 (5 years ago)
Author:
ged
Message:

Fixed ManyToMany relationships when not using the default schema (patch from
Diez B. Roggisch, closes ticket #48)

Files:
1 modified

Legend:

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

    r343 r345  
    702702        e1_desc = self.entity._descriptor 
    703703        e2_desc = self.target._descriptor 
     704 
     705        e1_schema = e1_desc.table_options.get('schema', None) 
     706        e2_schema = e2_desc.table_options.get('schema', None) 
     707        assert e1_schema == e2_schema, \ 
     708               "Schema %r for entity %s differs from schema %r of entity %s" \ 
     709               % (e1_schema, self.entity.__name__,  
     710                  e2_schema, self.target.__name__) 
    704711        
    705712        # First, we compute the name of the table. Note that some of the  
     
    775782                    fk_colnames.append(colname) 
    776783 
    777                     # Build the list of columns the foreign key will point 
    778                     # to. 
    779                     fk_refcols.append(desc.tablename + '.' + pk_col.key) 
     784                    # Build the list of column "paths" the foreign key will  
     785                    # point to 
     786                    target_path = "%s.%s" % (desc.tablename, pk_col.key) 
     787                    schema = desc.table_options.get('schema', None) 
     788                    if e1_schema is not None: 
     789                        target_path = "%s.%s" % (e1_schema, target_path) 
     790                    fk_refcols.append(target_path) 
    780791 
    781792                    # Build join clauses (in case we have a self-ref) 
     
    794805             
    795806            self.secondary_table = Table(tablename, e1_desc.metadata,  
    796                                          *args) 
     807                                         schema=e1_schema, *args) 
    797808 
    798809    def _reflect_table(self, tablename):