diff --git a/sqlalchemy_utils/path.py b/sqlalchemy_utils/path.py index 5780e2a..9538245 100644 --- a/sqlalchemy_utils/path.py +++ b/sqlalchemy_utils/path.py @@ -74,7 +74,7 @@ class AttrPath(object): "Invert failed because property '%s' of class " "%s has no backref." % ( prop.key, - prop.mapper.class_.__name__ + prop.parent.class_.__name__ ) ) return backref @@ -90,7 +90,7 @@ class AttrPath(object): if result[0] is self.parts[0]: class_ = self.class_ else: - class_ = result[0].mapper.class_ + class_ = result[0].parent.class_ return self.__class__( class_, self.path[slice] diff --git a/tests/test_path.py b/tests/test_path.py index cdccff3..0dac1bc 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -46,6 +46,7 @@ class TestAttrPath(TestCase): self.Document.sections, self.Section.subsections ] + assert str(path.path) == 'sections.subsections' def test_len(self): len(AttrPath(self.SubSection, 'section.document')) == 2 @@ -77,6 +78,8 @@ class TestAttrPath(TestCase): def test_getitem_with_slice(self): path = AttrPath(self.SubSection, 'section.document') assert path[:] == AttrPath(self.SubSection, 'section.document') + assert path[:-1] == AttrPath(self.SubSection, 'section') + assert path[1:] == AttrPath(self.Section, 'document') def test_eq(self): assert (