On Tue, Apr 3, 2018 at 6:20 AM, Julien Cigar <julien.ci...@gmail.com> wrote:
> On Thu, Mar 22, 2018 at 10:58:56AM +0100, Julien Cigar wrote:
>> On Tue, Mar 20, 2018 at 08:32:14PM -0400, Mike Bayer wrote:
>> > I think it would be a lot easier to have the corresponding translation
>> > linked off using relationship().   can you work with that?
>>
>
> Hello Mike,
>
> I tried with relationships, but I'm not too satisfied with the generated
> SQL, which makes me belived that I'm doing something wrong..
>
> I've GIST the relevant parts of my mappers and the generated SQL at
> https://gist.github.com/silenius/0fedf2bcb92b7e5c6f27732678c5baa0
>
> I'm wondering if overriding the 'translations' relationship as I do is
> the correct approach ..? In theory the "ContentTranslation" should be
> somewhat "dynamic", but I wonder if SQLAlchemy supports something like
> this .. ? By "dynamic" I mean it should be DocumentTranslation, or
> EventTranslation, ... regarding of the polymorphic_identity of the "other
> side" of the relationship

can you try making the "subclass" relationships under different names
so they definitely load individually?  or at least remove the
relationship that's in the base Content class.     I would need
working code to play with to figure out what might work.

>
> Thanks !
>
> Julien
>
>> I could .. :) I'll make some "helper functions" or maybe a custom Query
>> object, with maybe some proxy-like properties too
>>
>> Thanks
>>
>> >
>> > On Tue, Mar 20, 2018 at 9:19 AM, Julien Cigar <julien.ci...@gmail.com> 
>> > wrote:
>> > > Hello,
>> > >
>> > > I have an existing CMS-like application which uses joined table
>> > > inheritance at its core. Basically I have a base class Content from
>> > > which all other classes (Folder, Document, Event, File, ...) inherit.=20
>> > > It works wonderfully well. This is my (Postgre)SQL schema if you are=20
>> > > interested:=20
>> > > https://gist.githubusercontent.com/silenius/2e0f69fadfde9877e32c5b778efd39a=
>> > > f/raw/f08e2af2f7cd239c865777d1e54342ee53608520/sa.sql
>> > >
>> > > Now we'd like to support multiple languages. We plan to add an=20
>> > > additional table for each inherited class (additional translation=20
>> > > table approach), so basically we'll have something like:
>> > >
>> > > content_type
>> > >    |
>> > >    |
>> > > content --- content_translation
>> > >    |
>> > >    |
>> > > document --- document_translation
>> > >
>> > > Currently I have a polymorphic_on=3Dtables.content.c.content_type_id 
>> > > on=20
>> > > the base mapper (Content) and polymorphic_identity=3Dget_type_id(config,
>> > > 'some_content_type_name') for each inherited mapper (the get_type_id
>> > > function simply return the content_type ID:
>> > > https://gist.github.com/silenius/25b8f46192b5b9b23477fe0c541bd9f3 )
>> > >
>> > > As the application is quite large I'd like to avoid having to refactor a
>> > > lot of code.
>> > >
>> > > I wondered what would be the best SQLAlchemy approach to do this?
>> > >
>> > > For example let's say I have something like this in my application:
>> > > session.query(Document).all() which SQLAlchemy translates as:
>> > >
>> > > SELECT ..  FROM content=20
>> > > JOIN document ON content.id =3D document.content_id
>> > >
>> > > Is there some mapper configuration that I could change so that it
>> > > translates now as:
>> > >
>> > > SELECT .. FROM content=20
>> > > JOIN content_translation=20
>> > >     ON content.id =3D content_translation.content_id=20
>> > >     AND content_translation.lang =3D 'some_language_code'=20
>> > > JOIN document ON document.content_id =3D content.id=20
>> > > JOIN document_translation=20
>> > >     ON document_translation.document_id =3D document.content_id=20
>> > >     AND document_translation.lang =3D 'some_language_code'
>> > >
>> > > If not, what would be the best approach?
>> > >
>> > > Thanks !
>> > >
>> > >
>> > > --
>> > > 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 post to this group, send email to sqlalchemy@googlegroups.com.
>> > > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > > For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > 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 post to this group, send email to sqlalchemy@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> 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 post to this group, send email to sqlalchemy@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> 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 post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to