@classmethod<EOL><INDENT>def _construct_instance(cls, values):<DEDENT>
<EOL>items = values.items()<EOL>field_dict = dict([(cls._db_map.get(k, k),v) for k,v in items])<EOL>if cls._is_polymorphic:<EOL><INDENT>poly_key = field_dict.get(cls._polymorphic_column_name)<EOL>if poly_key is None:<EOL><INDENT>raise PolyMorphicModelException('<STR_LIT>')<EOL><DEDENT>poly_base = cls if cls._is_polymorphic_base else cls._polymorphic_base<EOL>klass = poly_base._get_model_by_polymorphic_key(poly_key)<EOL>if klass is None:<EOL><INDENT>poly_base._discover_polymorphic_submodels()<EOL>klass = poly_base._get_model_by_polymorphic_key(poly_key)<EOL>if klass is None:<EOL><INDENT>raise PolyMorphicModelException(<EOL>'<STR_LIT>'.format(poly_key, poly_base.__name__)<EOL>)<EOL><DEDENT><DEDENT>if not issubclass(klass, cls):<EOL><INDENT>raise PolyMorphicModelException(<EOL>'<STR_LIT>'.format(klass.__name__, cls.__name__)<EOL>)<EOL><DEDENT>field_dict = {k: v for k, v in field_dict.items() if k in klass._columns.keys()}<EOL><DEDENT>else:<EOL><INDENT>klass = cls<EOL><DEDENT>instance = klass(**field_dict)<EOL>instance._is_persisted = True<EOL>return instance<EOL>
method used to construct instances from query results
this is where polymorphic deserialization occurs