Skip to content

Commit

Permalink
Fix inherited model bind key support by setting it in __new__ and hoi…
Browse files Browse the repository at this point in the history
…sting it in __init__.
  • Loading branch information
dgilland committed Nov 17, 2014
1 parent 6cbbbfd commit 75aa113
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions alchy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ def __new__(mcs, name, bases, dct):
if not dct.get('__events__'):
dct['__events__'] = {}

if '__bind_key__' not in dct:
for base in base_dcts:
if '__bind_key__' in base:
dct['__bind_key__'] = base['__bind_key__']
break

return DeclarativeMeta.__new__(mcs, name, bases, dct)

def __init__(cls, name, bases, dct):
DeclarativeMeta.__init__(cls, name, bases, dct)

bind_key = None

for base in ([dct] + [base.__dict__ for base in bases]):
if '__bind_key__' in base:
bind_key = base['__bind_key__']
break

if bind_key is not None and hasattr(cls, '__table__'):
cls.__table__.info['bind_key'] = bind_key
if hasattr(cls, '__table__'):
if '__bind_key__' in dct:
cls.__table__.info['bind_key'] = dct['__bind_key__']

events.register(cls, dct)
events.register(cls, dct)


class ModelBase(object):
Expand Down

0 comments on commit 75aa113

Please sign in to comment.