Changeset 318

Show
Ignore:
Timestamp:
04/02/08 15:29:51 (5 years ago)
Author:
ged
Message:

Fixed multi-table inheritance when using a non default schema (closes #38)

Location:
elixir/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r314 r318  
     10.5.3 
     2 
     3Bug fixes: 
     4- Fixed multi-table inheritance when using a non default schema (closes #38) 
     5 
    160.5.2 - 2008-03-28 
    27 
  • elixir/trunk/elixir/entity.py

    r308 r318  
    197197                    # key columns  
    198198                    parent_desc = self.parent._descriptor 
     199                    schema = parent_desc.table_options.get('schema', None) 
     200                    tablename = parent_desc.tablename  
     201                    if schema is not None: 
     202                        tablename = "%s.%s" % (schema, tablename) 
    199203                    for pk_col in parent_desc.primary_keys: 
    200204                        colname = options.MULTIINHERITANCECOL_NAMEFORMAT % \ 
     
    205209                        # a real column object when said column is not yet  
    206210                        # attached to a table 
    207                         pk_col_name = "%s.%s" % (parent_desc.tablename,  
    208                                                  pk_col.key) 
     211                        pk_col_name = "%s.%s" % (tablename, pk_col.key) 
    209212                        fk = ForeignKey(pk_col_name, ondelete='cascade') 
    210213                        col = Column(colname, pk_col.type, fk, 
  • elixir/trunk/tests/test_inherit.py

    r313 r318  
    99def setup(): 
    1010    metadata.bind = 'sqlite:///' 
    11 #    metadata.bind = 'postgres://localhost/test' 
     11#    metadata.bind = 'postgres://@/test' 
    1212#    metadata.bind.echo = True 
    1313    elixir.options_defaults['shortnames'] = True 
     
    104104        # enforcing the foreign key constraint cascade rule). 
    105105#        assert not B.table.select().execute().fetchall() 
     106     
     107    def test_inheritance_wh_schema(self): 
     108        # I can only test schema stuff on postgres 
     109        if metadata.bind.name != 'postgres': 
     110            print "schema test skipped" 
     111            return 
     112         
     113        class A(Entity): 
     114            using_options(inheritance="multi") 
     115            using_table_options(schema="test") 
     116 
     117            row_id = Field(Integer, primary_key=True) 
     118            thing1 = Field(String(20)) 
     119 
     120        class B(A): 
     121            using_options(inheritance="multi") 
     122            using_table_options(schema="test") 
     123 
     124            thing2 = Field(String(20)) 
     125 
     126        setup_all(True) 
    106127 
    107128    def test_inverse_matching_on_parent(self):