Skip to content

Commit

Permalink
inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
evertheylen committed Apr 28, 2016
1 parent 06b6d9b commit 1b17c79
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions sparrow/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ def __new__(self, name, bases, dct):
p = full_dct[k]
if hasattr(p, "__postinited__") and p.__postinited__:
p = copy.deepcopy(p)
full_dct[k] = p
dct[k] = p
# Set some stuff of properties that are not known at creation time
p.name = k
p.__postinit__()
Expand All @@ -468,6 +470,8 @@ def __new__(self, name, bases, dct):
r = full_dct[k]
if hasattr(r, "__postinited__") and r.__postinited__:
r = copy.deepcopy(r)
full_dct[k] = r
dct[k] = r
r.name = k
r.__postinit__()
refs.append(r)
Expand Down Expand Up @@ -540,13 +544,16 @@ def __metainit__(obj, db_args=None, json_dict=None, **kwargs):

dct["__metainit__"] = __metainit__

if "key" in dct:
the_key = dct["key"]
if "key" in full_dct:
the_key = full_dct["key"]
if hasattr(the_key, "__postinited__") and the_key.__postinited__:
the_key = copy.deepcopy(the_key)
the_key.__postinit__()
dct["key"] = the_key
full_dct["key"] = the_key
dct["_incomplete"] = isinstance(the_key, KeyProperty)
else:
assert "key" in full_dct, "Each class must have a key"
the_key = full_dct["key"]
assert False, "Each class must have a key" # TODO

dct["_complete_props"] = [p for p in props if not isinstance(p, KeyProperty)]

Expand All @@ -564,6 +571,8 @@ def __metainit__(obj, db_args=None, json_dict=None, **kwargs):

for p in props:
p.cls = cls
if isinstance(cls.key, Property):
cls.key.cls = cls

cls._create_table_command = CreateTable(cls).to_raw()
cls._drop_table_command = DropTable(cls).to_raw()
Expand Down

0 comments on commit 1b17c79

Please sign in to comment.