On 01/14/2015 11:40 AM, Mehdi wrote:
OK, I misunderstood the joining concept. if i do like below
everything's fine:
|
session.query(MyTable).join(Given,Mytable.given_id==Given.gid).filter(Given.given.col_1
=="value")
|
But i wonder why sqlalchemy doesn't support query like this?
|
session.query(MyTable).filter(MyTable.relation1.col_a=="value")
|
I think an orm should works more object-oriented and pythonic rather
sql-ish! why i have to use join while i already define relation in my
model?
You can join a table in different ways, which need to be specified. You
can join with less key strokes by:
session.query(MyTable).join(Given)
assuming you have the appropriate relationship's set up
On Tuesday, January 13, 2015 at 10:05:38 PM UTC+3:30, Mehdi wrote:
Hi
I am looking for a solution to make two separate tables(at sql
defenition level) query-able at orm level.
There is a give database which i have no right to change existing
tables and i just add two tables to it which one of my tables have
a column holding id value of a table in give db:
|
classGiven(Base):
__tablename__ ="given_table"
gid =Column(Integer,primary_key=True)
col_1 =...
col_2 =...
...
classMyTable(Base):
__tablename__ ="my_table"
id =Column(Integer,primary_key=True)
given_id =Column(Integer)
...
|
I've managed to fill *'given_id'* column with proper *'gid'* based
on some conditions. but with or without '*given_id'* column, i am
looking for a way to have *'Given'* model joinable and query-able
by sqlalchemy. i.e:
|
session.query(MyTable).filter(MyTable.given.col_1 =="value")
|
I'm not sure how could i use hybrid property or any other way for
this situation.
Please help me.
--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto: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.