Skip to content

Commit efa67fa

Browse files
committed
start implement custom identifier
1 parent 8497e0c commit efa67fa

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

graphene/contrib/sqlalchemy/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class SQLAlchemyOptions(ObjectTypeOptions):
1010
def __init__(self, *args, **kwargs):
1111
super(SQLAlchemyOptions, self).__init__(*args, **kwargs)
1212
self.model = None
13+
self.identifier = None
1314
self.valid_attrs += VALID_ATTRS
1415
self.only_fields = None
1516
self.exclude_fields = []

graphene/contrib/sqlalchemy/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ class Meta:
113113
def get_node(cls, id, info=None):
114114
try:
115115
model = cls._meta.model
116+
identifier = cls._meta.identifier or "id"
116117
query = get_query(model, info)
117-
instance = query.filter(model.id == id).one()
118+
instance = query.filter(getattr(model, identifier) == id).one()
118119
return cls(instance)
119120
except NoResultFound:
120121
return None

0 commit comments

Comments
 (0)