sqlalchemy - How to instead of 'query.add_column' add field to entity? -
i have sqlalchemy query:
>>> items = ( company.query .add_column(address.city) .join(company.address) .filter(and_( ...some filters... )) .all() ) >>> items [(company(6239), berlin), (company(5388), moscow), ...]
how can modify query, put address.city entity company? want as:
... >>> items [company(6239), company(5388), ...] >>> items[0].city berlin
thank you.
i not think can directly in query without modifying model.
can achive in code:
>>> items [(company(6239), berlin), (company(5388), moscow), ...] >>> # set company >>> (_company, _city) in items: _company.city = _city >>> # remove city attribute >>>> items = [_company (_company, _city) in items] >>> items [company(6239), company(5388), ...] >>> items[0].city berlin
Comments
Post a Comment