Closed ADR-007 closed 1 year ago
I'm thinking about the right way to implement things like Model.collection.get_by_id(<id>).
Model.collection.get_by_id(<id>)
Option 1: Add _by_id suffix Examples:
_by_id
Model.collection.get(<key>) Model.collection.get_by_id(<id>)
Option 2: Add the "overloaded" versions of the methods: Examples:
Model.collection.get(<key>) Model.collection.get(<id>) Model.collection.get(key=<key>) Model.collection.get(id=<id>)
Implementation (fully supported by mypy):
@overload def get(self, key, transaction=None): ... @overload def get(self, id, transaction=None): ... @convert_key_or_id_to_key def get(self, key, transaction=None): """Get document from firestore""" return self.queryset.get(key, transaction)
I think I prefer "option 2" but not sure yet. 🤔
Affected methods in Manager:
Any suggestions?
Hmmm... Option 2 looks great.
I'm thinking about the right way to implement things like
Model.collection.get_by_id(<id>)
.Option 1: Add
_by_id
suffix Examples:Option 2: Add the "overloaded" versions of the methods: Examples:
Implementation (fully supported by mypy):
I think I prefer "option 2" but not sure yet. 🤔
Affected methods in Manager:
Any suggestions?