On Tue, Jan 26, 2021, at 7:31 PM, Kent Bower wrote:
> I should have given these details from the get-go:  the use case is a 
> specialized select() (dynamically built) which would be extremely convenient 
> to map relationships against for convenience in subquery loading, etc. So, 
> the class would not already have a mapper.  Can I pass non_primary=True 
> anyway, or won’t this work?

You can use relationship loading with the aliased class approach too; the 
relationships that are on the class would just work against your altered 
select() statement.  Also I would recommend ditching subqueryloading in favor 
of selectinload() , which is better than subqueryload in pretty much every way.

if you want to make totally custom relatoinships to new classes that aren't on 
the class normally, and such and have different primaryjoin conditions and all 
that, and it's not possible to have these relationships at least as 
placeholders on the normal class, then it starts to look like you want to make 
a subclass and map to that with concrete=True.


> 
> 
> On Tue, Jan 26, 2021 at 6:18 PM Mike Bayer <[email protected]> wrote:
>> __
>> 
>> 
>> On Tue, Jan 26, 2021, at 3:16 PM, Kent wrote:
>>> Question: if I add a mapper to a class that is only needed temporarily, 
>>> does using the mapper compile it along side my "normal" mappers such that 
>>> I'll leak memory when I mean for the class to be garbage collected?
>>> 
>>> Put another way, can I add a mapper to a class that doesn't influence my 
>>> "main mappers" and gets thrown away when the class is thrown away or is 
>>> that not possible?
>> 
>> Assuming the class already has a mapper, and this is an additional mapper 
>> that maps the class in a different way, this feature is called a 
>> "non-primary mapper" and requires that you pass the non_primary=True flag.   
>>  If you are using non-primary mappers, then yes they get garbage collected.
>> 
>> This is also a deprecated feature that won't be in SQLAlchemy 2.0.    The 
>> only use case we can identify for "non-primary mappers" is when you want to 
>> create a relationship() to one, and for that use case we now support the 
>> "Relationship to AliasedClass" pattern.
>> 
>> For anything else involving retrieving a class from an alternate selectable 
>> of some kind, you should be able to use AliasedClass for, e.g. 
>> sqlalchemy.orm.aliased(), so I would recommend using that instead unless you 
>> are on a very old version of SQLAlchemy.
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Thanks in advance,
>>> Kent
>>> 

>>> -- 
>>> 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 [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/df03ce24-3986-450c-8c3a-a020d5d6adccn%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/sqlalchemy/df03ce24-3986-450c-8c3a-a020d5d6adccn%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> 
>> 

>> -- 
>> 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 a topic in the 
>> Google Groups "sqlalchemy" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/sqlalchemy/IAqOQFpiB20/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/c8f7f84e-af90-450c-9289-ed84fc6996a9%40www.fastmail.com
>>  
>> <https://groups.google.com/d/msgid/sqlalchemy/c8f7f84e-af90-450c-9289-ed84fc6996a9%40www.fastmail.com?utm_medium=email&utm_source=footer>.
> 

> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/CANnF6aEAcuCRJrAQDWYrDGVmv5k7OuXNC_AXgrqDO00L3j%3D%2BAg%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/CANnF6aEAcuCRJrAQDWYrDGVmv5k7OuXNC_AXgrqDO00L3j%3D%2BAg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/c3782de7-cfdf-40d2-b28c-3f5b8c7f319c%40www.fastmail.com.

Reply via email to