On 6/17/15 12:12 PM, [email protected] wrote:
Hi all,
I was giving SQLAlchemy 1.0 series a try but I have found some
problems along
the way. There are some queries that in the 0.9.9 version used to
work, but
they do not work as expected anymore. An example of one of those is:
|
feeds =DBSession.query(Feed,Client,ClientPro).outerjoin(
Client,Client.id ==Feed.clientid).outerjoin(
ClientPro,ClientPro.clientid ==Client.id)
|
and it used to return:
|
SELECT feed.id AS feed_id,feed.clientid AS feed_clientid ...
FROM feed
LEFT OUTER JOIN client ON client.id =feed.clientid
LEFT OUTER JOIN clientpro ON clientpro.clientid =client.id
|
But since I changed to 1.0 series it returns:
|
SELECT feed.id AS feed_id,feed.clientid ...
FROM feed
LEFT OUTER JOIN client ON client.id =feed.clientid AND NULL
LEFT OUTER JOIN clientpro ON clientpro.clientid =client.id AND NULL
|
Obvously SQLAlchemy isn't doing this without some direction from your
own application. The example code you've given illustrates nothing
that would cause this effect, so would need an actual reproducing test case.
I have tested it from version 1.0.0 to 1.0.5 and it returns the same
SQL query
in all of them.
The relevant part of the models.py file is:
|
classFeed(Base,ModelBase):
__tablename__ ='feed'
id =Column(Integer,primary_key=True)
clientid =Column(Integer,ForeignKey('client.id'),nullable=False)
...
classClient(Base,ModelBase):
__tablename__ ='client'
id =Column(Integer,primary_key=True)
...
classClientPro(Base,ModelBase):
__tablename__ ='clientpro'
id =Column(Integer,primary_key=True)
clientid
=Column(Integer,ForeignKey('client.id',ondelete='CASCADE'),nullable=False)
...
|
These fragments of code illustrate nothing that would cause such an effect:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Feed(Base):
__tablename__ = 'feed'
id = Column(Integer, primary_key=True)
clientid = Column(Integer, ForeignKey('client.id'), nullable=False)
class Client(Base):
__tablename__ = 'client'
id = Column(Integer, primary_key=True)
class ClientPro(Base):
__tablename__ = 'clientpro'
id = Column(Integer, primary_key=True)
clientid = Column(Integer, ForeignKey('client.id',
ondelete='CASCADE'), nullable=False)
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
sess = Session(e)
q = sess.query(Feed, Client, ClientPro).outerjoin(
Client, Client.id == Feed.clientid).outerjoin(
ClientPro, ClientPro.clientid == Client.id)
print(q)
result = q.all()
output:
SELECT feed.id AS feed_id, feed.clientid AS feed_clientid, client.id AS
client_id, clientpro.id AS clientpro_id, clientpro.clientid AS
clientpro_clientid
FROM feed LEFT OUTER JOIN client ON client.id = feed.clientid LEFT OUTER
JOIN clientpro ON clientpro.clientid = client.id
2015-06-17 13:03:18,335 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2015-06-17 13:03:18,336 INFO sqlalchemy.engine.base.Engine SELECT
feed.id AS feed_id, feed.clientid AS feed_clientid, client.id AS
client_id, clientpro.id AS clientpro_id, clientpro.clientid AS
clientpro_clientid
FROM feed LEFT OUTER JOIN client ON client.id = feed.clientid LEFT OUTER
JOIN clientpro ON clientpro.clientid = client.id
--
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.