On Wed, Apr 11, 2018 at 6:15 AM, Julien Cigar <[email protected]> wrote:
> On Tue, Apr 10, 2018 at 11:53:09AM -0400, Mike Bayer wrote:
>> On Tue, Apr 10, 2018 at 9:28 AM, Julien Cigar <[email protected]> wrote:
>> > Hello,
>> >
>> > I wondered if it is possible to use a class mapped against multiple
>> > tables as a relationship() in another class?
>>
>> it is, there's examples at
>> http://docs.sqlalchemy.org/en/latest/orm/join_conditions.html#relationship-to-non-primary-mapper
>>
>> that is map your related class to whatever you want in a non primary
>> mapper.   If you are just selecting data you have a lot of options.
>>
>
> Hi Mike,
>
> Thanks for the link :) I tried and it seems to work,  except in an
> inheritance scenario (1). I guess that in a non primary mapper I can't
> put my polymorphic_on condition on a Join clause?
>
> (1) https://gist.github.com/silenius/a237baf8c4bcd79550dc884f2eeb1998

this is a lot of code to follow, but if the point of the mutli-table
thing you're doing is to game the joined inheritance into doing
something, then that's probably not the appropriate use for it.   It
looks like you're trying to add all kinds of columns to
"ContentTranslation" from the other mappers like Content.


>
> Thanks!
> Julien
>
>>
>> >
>> > something like:
>> >
>> > ### Content
>> >
>> > content_translation_join = sql.join(
>> >   t_content, t_content_translation
>> > )
>> >
>> > orm.mapper(
>> >   ContentTranslation, content_translation_join,
>> >   polymorphic_on=t_content.c.content_type_id
>> > )
>> >
>> > orm.mapper(
>> >   Content, t_content,
>> >   polymorphic_on=t_content.c.content_type_id,
>> >   properties={
>> >     'translations': orm.relationship(
>> >       ContentTranslation,
>> >       # more stuff here
>> >     )
>> >   }
>> > )
>> >
>> > ### Document
>> >
>> > orm.mapper(
>> >   DocumentTranslation, t_document_translation,
>> >   inherits=ContentTranslation,
>> >   polymorphic_identity=some_id
>> > )
>> >
>> > orm.mapper(
>> >   Document, t_document,
>> >   inherits=Content,
>> >   polymorphic_identity=some_id
>> > )
>> >
>> > I tried (1) but it doesn't seems to work so I want to be sure that it's
>> > not possible :)
>> >
>> > Thanks!
>> > Julien
>> >
>> > (1) 
>> > https://gist.github.com/silenius/561b13f4b987c36434cd81e2c08cab6e#file-foo-py
>> >
>> >
>> >
>> > --
>> > 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 [email protected].
>> > To post to this group, send email to [email protected].
>> > 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to