Using the wrap method in Query breaks the return_models functionality of the select method.
>>> q = Query().from_table(Rating).limit(1).wrap()
>>> q.select(return_models=True)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-afd37124e1a1> in <module>()
----> 1 q.select(return_models=True)
/usr/local/lib/python3.4/dist-packages/querybuilder/query.py in select(self, return_models, nest, bypass_safe_limit, sql, sql_args)
1555 # create models if needed
1556 if return_models:
-> 1557 model_class = self.tables[0].model
1558 new_rows = []
1559 for row in rows:
AttributeError: 'QueryTable' object has no attribute 'model'
It's possible to work around the issue by assigning the model attribute manually.
>>> q = Query().from_table(Rating).limit(1).wrap()
>>> q.tables[0].model = Rating
>>> q.select(return_models=True)
[<Rating: Rating object>]
Using the Query without wrapping it works as expected.
>>> q = Query().from_table(Rating).limit(1)
>>> q.select(return_models=True)
[<Rating: Rating object>]
Thanks for the awesome library, it has saved me a lot of effort!
Using the
wrapmethod inQuerybreaks thereturn_modelsfunctionality of theselectmethod.It's possible to work around the issue by assigning the
modelattribute manually.Using the
Querywithout wrapping it works as expected.Thanks for the awesome library, it has saved me a lot of effort!