On May 10, 2014, at 7:13 PM, Richard Gerd Kuesters <rich...@humantech.com.br> 
wrote:

> hi all!
> 
> situation: i'm mapping a select as a class, using mapper. so far so good.
> 
> problem: some of my selected columns *are* foreign keys in their respective 
> tables, but i would like to say to sqla that they're foreign keys to another 
> mapped class, which have the pks from which those fks are pointing.
> 
> the first question is: how? or
> 

should be able to use relationship(), set up primaryjoin with foreign()

        foo = relationship("Remote", primaryjoin=myselect.c.foo == 
foreign(table.c.foo))

it's a little weird i guess, should work out in modern versions 


> the second question: is there a way to inherit properties (like fks) OR 
> "cheat" declaring foreign keys that doesn't exists at the database level ?
> 
> 

sure, use ForeignKey() on your Column(), doesn't matter if it's not in the DB, 
or use in relationship foreign_keys / foreign() annotation





>  
> my best regards,
> 
> richard.
> 
> 
> -- 
> 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 http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to