I think I get the idea. That's why the properties with
hybrid_property.expression defined are able to work as SQL SELECT fields in
the cases where a tuple is returned rather than an ORM model... because you
don't have to have a place in _dict__ to put it, it just goes into the
tuple.
My main
I think the thing you need to understand about the "hybrid" is that it isn't
"loaded" with the object, that is, it has no place in __dict__ to be stored.
The function that you create is invoked every time you access it on your object
or class. If you have an object instance of Task, as you've
I thought I figured out another clever way, but it's not working working as
I thought it might. Thought maybe using ".from_self" I could do the base
full automatic ORM Model query to get everything, then do the .from_self to
wrap it with an outer query and only return the columns I need.
I think it's starting to make sense. I did misunderstand exactly when the
.expression SQL was used - I had thought even queries for ORM models would
use it, but I see it does work as you describe.
My goal is to return a subset of fields and make that query building
operation be dynamic and
well hybrids don't apply to a load_only operation because they are not included
in the query that emits when the ORM SELECTs for an object. that is,
@hybrid_property.expression gives you a SQL expression, but that's never
included when you say session.query(Task). It's only if you said,
I should at least clarify that I have @hybrid_test.expression in place for
that property and it works when I just do the base 'get me everything'
query.
On Monday, June 3, 2019 at 2:13:17 PM UTC-4, Gmoney wrote:
>
> I'm trying to use load_only and was able to get a really basic example to
>