Skip to content

Commit

Permalink
refactor: Update inspection mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbukachi committed Mar 15, 2023
1 parent 48f45a1 commit 46f2ddd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sqlalchemy_mixins/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def primary_keys(cls):
def relations(cls):
"""Return a `list` of relationship names or the given model
"""
return [c.key for c in cls.__mapper__.iterate_properties
return [c.key for c in cls.__mapper__.attrs
if isinstance(c, RelationshipProperty)]

@classproperty
Expand Down
7 changes: 1 addition & 6 deletions sqlalchemy_mixins/tests/test_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method
from sqlalchemy.orm import sessionmaker, configure_mappers, DeclarativeBase
from sqlalchemy.orm import sessionmaker, DeclarativeBase

from sqlalchemy_mixins import InspectionMixin

Expand Down Expand Up @@ -61,11 +61,6 @@ class ModelWithTwoPks(BaseModel):
pk2 = sa.Column(sa.Integer, primary_key=True)


# For sqlalchemy >= 2.0. This call is required in order to configure
# relationships created from backrefs
configure_mappers()


class TestSessionMixin(unittest.TestCase):
def setUp(self):
Base.metadata.create_all(engine)
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_mixins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_relations(cls):
mapper = cls
else:
mapper = cls.__mapper__
return [c for c in mapper.iterate_properties
return [c for c in mapper.attrs
if isinstance(c, RelationshipProperty)]


Expand Down

0 comments on commit 46f2ddd

Please sign in to comment.