Funny enough, this is what I tried. I just wrote up a small sample script 
using defaultload + load_only and sure enough it works. There must be 
something in the code base I'm working with that prevents the load_only bit 
from being applied. I'm pretty sure defaultload is woroking fine. I'll 
report back if I find it.

Thanks for clarifying!

On Thursday, January 5, 2023 at 8:14:21 AM UTC+8 Michael Bayer wrote:

> yeah you can use defaultload.load_only
>
>
> defaultload(ModelA.model_b).load_only(ModelB.only_field)
>
>
>
> On Wednesday, January 4, 2023 at 3:15:02 AM UTC-5 to...@revenuecat.com 
> wrote:
>
>> Hi,
>>
>> This might be a strange question, but I tried to find this in the 
>> documentation to no avail.
>>
>> Is it possible to use something like load_only to override which columns 
>> are loaded in when loading a relationship (as in, a relationship that is 
>> not loaded at first with the original query)?
>>
>> Something like:
>> class ModelB:
>>   ...
>>
>> class ModelA:
>>   model_b = relationship("ModelB")
>>
>> model_a = 
>> session.query(ModelA).options(load_only(Model_b.only_field_i_want_in_the_future)).filter(ModelA.id==1).first()
>>
>> It's a bit strange, but I want to ensure if someone loads the model_b 
>> property in the future, only specific columns are loaded in at first.
>>
>> I can do this if I just query for model_b via the foreign key instead of 
>> using the relationship property, but I'd like to avoid that if possible.
>>
>> Sorry if this question is a bit weird/confusing, it's kind of a strange 
>> use case.
>>
>> Thanks,
>> Tony
>>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/f7159223-31f1-4f0e-9cb1-600e7fd517b5n%40googlegroups.com.

Reply via email to