The selection of specific columns in SQLAlchemy in scalars does not work

21 Views Asked by At

When writing a query with specific columns in select, I get only the first element that I specified in it. That is, such a code

query = select(self.model.name, self.model.price).join(CategoryRepository.model).join(
ImageRepository.model, is outer=True)
print((await self._session.scalars(query)).all())

Returns ['Shoes', 'Dress', 'Pendant'] - only the names, although the sql code generates the correct one. And when calling execute, everything works correctly

print((await self._session.execute(query)).all())

Returns [('Dress', 350.0199890136719), ('Shoes', 300.04998779296875), ('Pendant', 99.98999786376953)]

0

There are 0 best solutions below