You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to how the 2.0 syntax works and using asyncpg writing generic helper methods when using relationships becomes a lot trickers. Essentially you have to write a select as follows:
for the relationships to work. This makes writing generic CRUD wrapper difficult.
The proposal here is to write a generic method called _get_select which provides the joined configuration of the select statement which other get methods can use to apply conditions to e.g:
each class inheriting from the ModelCRUDMixin can override that to provide the appropriate configuration, allowing the global getting to work across models and making it easier to write other getters.
Another benefit of this approach will be that as the relationships are modified they can be changed in one spot and all other getters remain unchanged.
asyncpg does not support joinload and requires queries to use the selectinload option
to construct queries which loads the relationship data.
it's likely that each model will have more than one getter, this pattern (documented)
allows you to construct the base query (which can be overridden) and then each
getter uses this inturn allowing you to maintain the selectinload code in one spot.
the method in the package simply refreshed the model
post create and returned it to the calling function, while this will load the
identifier but it won't load any dynamically configured relationships
we previous fixed this by introducing a _base_get_query in issue #41
the create method now calls the method to get a fully populated
model
Due to how the
2.0
syntax works and usingasyncpg
writing generic helper methods when using relationships becomes a lot trickers. Essentially you have to write aselect
as follows:for the relationships to work. This makes writing generic
CRUD
wrapper difficult.The proposal here is to write a generic method called
_get_select
which provides thejoined
configuration of theselect
statement which otherget
methods can use to apply conditions to e.g:a refactored version would then look like
each class inheriting from the
ModelCRUDMixin
can override that to provide the appropriate configuration, allowing the global getting to work across models and making it easier to write other getters.Another benefit of this approach will be that as the relationships are modified they can be changed in one spot and all other getters remain unchanged.
See also #38
The text was updated successfully, but these errors were encountered: