On Fri, Sep 27, 2019, at 9:59 AM, Mike Bayer wrote:
> 
> 
> On Fri, Sep 27, 2019, at 9:34 AM, Julien Cigar wrote:
>> On Fri, Sep 27, 2019 at 09:03:53AM -0400, Mike Bayer wrote:
>> > 
>> > 
>> > On Fri, Sep 27, 2019, at 6:26 AM, Julien Cigar wrote:
>> > > On Thu, Sep 26, 2019 at 11:39:52AM -0400, Mike Bayer wrote:
>> > > > that's not supported, I would suggest trying to solve your problem in 
>> > > > a different way.
>> > > > 
>> > > 
>> > > Ok, that's what I thought.. thanks!
>> > > 
>> > > I have a typical joined table inheritance, with Content being the "base"
>> > > class, and childs as Document, Folder, Event, etc.
>> > > 
>> > > I have added a transparent translation package with the "one translation
>> > > table per entity" approach (also using joined table inheritance),
>> > > and hybrid properties. 
>> > > 
>> > > So I have ContentTranslation being the "base" class, and childs like 
>> > > DocumentTranslation, FolderTranslation, EventTranslation, etc. which
>> > > contain translation fields specific to each class.
>> > > 
>> > > You helped me some weeks ago on this and I ended with (1), in which two 
>> > > relationships were added to every children of Content
>> > > ("current_translation" and "translations"), and hybrid properties
>> > > pointing to their dedicated translation class. 
>> > > 
>> > > It works well, the only minor issue is that I don't have any
>> > > relationship on the base Content class (as you told me in the past that
>> > > overriding relationships could be problematic).
>> > > 
>> > > I made some modifications (2) in which the relationships are now
>> > > prefixed with the class name, and added two properties which point to
>> > > the class relationship, so that in the end:
>> > > 
>> > > - Content has a "content_current_translation" and 
>> > > "content_translations" relationships, and two property
>> > > "current_translation" and "translations" pointing to them
>> > > 
>> > > - Document has a "document_current_translation" and
>> > > "document_translations" with also two property current_translation and
>> > > translations pointing to them, but the minor issue is that the
>> > > content_current_translation is also joined loaded, which I'd like to
>> > > avoid.. and I'm wondering what would be the best approach.
>> > > 
>> > > I don't know if it's clear, but if it is not I could make a test case
>> > 
>> > I'm not sure what the problem is, the code I can see has "lazy='joined'" 
>> > in some spots, you'd make that into "lazy='select'" if that's the lazy 
>> > loading you want. 
>> > 
>> > if this is some kind of automatic-generation issue where some of these 
>> > generations need to apply a different kind of default loader then you 
>> > would need to add parameterization to your code generation scheme, such as 
>> > additional arguments to your setup_relationships() function.
>> 
>> The problem I have if that the "current_translation" should always be
>> lazy='joined' within it's context.
>> 
>> In the base class (Content) "current_translation" points to the
>> "content_current_translation" relationship. In a child class (Document)
>> "current_translation" points to "document_current_translation"
>> relationship, but a child class also contain the 
>> "content_current_translation", as Document inherits from Content and
>> that the property has already been setup. 
>> So both relationships are joinedloaded at the same time when I'm 
>> session.query(Document).
> 
> 
> there's no way I'm going to parse that without spending a long time looking 
> at an example, sorry I know we keep coming back to this code that you've been 
> working on but it's not something i can keep in my head in the interim.
> 
>> 
>> For example when I'm querying for a Document SQLAlchemy generates two
>> queries for the translations (1) and (2). The JOIN on the
>> document_translation table should happend in (1).
>> 
>> When I'm setting the mapping for a child class (Document, Event, Folder,
>> etc) I'm looking for a way to either 1) remove the 
>> "content_current_translation" relationship or 2) disable joined loading 
>> for this relationship.
>> 
>> But when I'm dbsession.query(Content) the "content_current_translation"
>> must be joined loaded
> 
> so my vague understanding is that you want a certain relationship to 
> joinedload when its at the top level, but not joinedload when it's deeper 
> down the stack, is that the general idea?
> 
> there might be some ways to approach this but also I think you should be able 
> to override the relationship() entirely on your subclass, if that works. I 
> just tried getting a proof of concept going but it doesnt seem to illustrate 
> the thing I'm going for, I can't get it to generate too many joins to start 
> with for some reason.
> 
> There's also other possible ways such as setting up query.options() within a 
> before_compile() listener.
> 
> 
> As always, this is way too complicated for me to understand from fragments 
> alone. I'm not even sure why my own simple proof of concept is doing 
> something that it's doing and I don't have time to pdb into joinedloader 
> today.

oh, my POC had a cycle in it and the joinedloader catches those :)



> 
> 
> 
>> 
>> (1) https://gist.github.com/silenius/482f6a0f46427580aae12ba32b836ee5
>> (2) https://gist.github.com/silenius/511f3069a871dd17d6e202c6b92edaf8
>> 
>> > 
>> > 
>> > > 
>> > > (1) 
>> > > https://github.com/silenius/amnesia_multilingual/blob/master/amnesia_multilingual/builders.py
>> > > 
>> > > (2) 
>> > > https://github.com/silenius/amnesia_multilingual/blob/dev/amnesia_multilingual/builders.py
>> > > 
>> > > Thank you :)
>> > > 
>> > > Julien
>> > > 
>> > > > 
>> > > > 
>> > > > On Thu, Sep 26, 2019, at 11:25 AM, Julien Cigar wrote:
>> > > > > Hello,
>> > > > > 
>> > > > > I'd like to change a lazy property of an existing relationship (from
>> > > > > 'joined' to 'noload'). I tried the following:
>> > > > > 
>> > > > > mapper = orm.class_mapper(MyClass)
>> > > > > prop = mapper.get_property('some_relationship')
>> > > > > prop.lazy = 'noload'
>> > > > > 
>> > > > > but it doesn't seems to work, as the property is still loaded
>> > > > > 
>> > > > > Any idea if this is possible?
>> > > > > 
>> > > > > Thanks,
>> > > > > Julien
>> > > > > 
>> > > > > 
>> > > > > -- 
>> > > > > Julien Cigar
>> > > > > Belgian Biodiversity Platform (http://www.biodiversity.be)
>> > > > > PGP fingerprint: EEF9 F697 4B68 D275 7B11 6A25 B2BB 3710 A204 23C0
>> > > > > No trees were killed in the creation of this message.
>> > > > > However, many electrons were terribly inconvenienced.
>> > > > > 
>> > > > > -- 
>> > > > > 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/20190926152504.GB1535%40p52s.
>> > > > > 
>> > > > 
>> > > > -- 
>> > > > 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/dab6e523-675f-4a88-aa6d-c303360a50e6%40www.fastmail.com.
>> > > 
>> > > -- 
>> > > Julien Cigar
>> > > Belgian Biodiversity Platform (http://www.biodiversity.be)
>> > > PGP fingerprint: EEF9 F697 4B68 D275 7B11 6A25 B2BB 3710 A204 23C0
>> > > No trees were killed in the creation of this message.
>> > > However, many electrons were terribly inconvenienced.
>> > > 
>> > > -- 
>> > > 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/20190927102658.GA16334%40home.lan.
>> > > 
>> > > 
>> > > *Attachments:*
>> > > * signature.asc
>> > 
>> > -- 
>> > 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/31539116-6f4d-4ed3-84cd-e0111c5b69b0%40www.fastmail.com.
>> 
>> -- 
>> Julien Cigar
>> Belgian Biodiversity Platform (http://www.biodiversity.be)
>> PGP fingerprint: EEF9 F697 4B68 D275 7B11 6A25 B2BB 3710 A204 23C0
>> No trees were killed in the creation of this message.
>> However, many electrons were terribly inconvenienced.
>> 
>> -- 
>> 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/20190927133408.GB16334%40home.lan.
>> 
>> 
>> *Attachments:*
>>  * signature.asc
> 
> 

> --
>  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/956f4c7a-7e27-41ec-a623-a8d98b9d67a6%40www.fastmail.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/956f4c7a-7e27-41ec-a623-a8d98b9d67a6%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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/631f8abf-1ab0-4f13-a433-772c947eb82d%40www.fastmail.com.

Reply via email to