Hi
SQLAlchemy 0.8.2, Win32,
Microsoft "SQL Server" ODBC Driver

Briefly...

class Uno(Base):
    __tablename__ = 'UNO'
    __table_args__ = {
        'autoload':True,
        'autoload_with':engine
        }
    duos = relationship("DuoDuo",backref=backref("duos"))


print session.query(Uno, Uno.duos).all()

sqlalchemy gets it wrong:

SELECT [DUO_DUO].[ID] = [UNO].[DUO_DUO] AS duos 
FROM [DUO_DUO], [UNO]

This seems to work fine on linux with unixodbc/freetds.

I'm stuck. I've tried to create a testcase. Is there anything else that 
would be helpful?

-- 
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/groups/opt_out.
---CREATE DATABASE [TestDataBase] ON  PRIMARY 

USE [TestDataBase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


------------------------
CREATE TABLE [dbo].[DUO_DUO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[STUFF] [nvarchar](50) NULL,
 CONSTRAINT [PK_DUO_DUO] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

GO


-------
CREATE TABLE [dbo].[UNO](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[DUO_DUO] [int] NOT NULL,

 CONSTRAINT [PK_UNO] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY] 

GO

ALTER TABLE [dbo].[UNO]  WITH CHECK ADD CONSTRAINT [FK_TestDataBase_DUO_DUO] FOREIGN KEY([DUO_DUO])
REFERENCES [dbo].[DUO_DUO] ([ID])
GO

ALTER TABLE [dbo].[UNO] CHECK CONSTRAINT [FK_TestDataBase_DUO_DUO]
GO

-----

insert into duo_duo
(stuff)
values
('foo')

insert into duo_duo
(stuff)
values
('bar')

insert into uno
(duo_duo)
values
(1)

insert into uno
(duo_duo)
values
(2)
---
select *
from
uno u
inner join duo_duo d
on u.duo_duo = d.id

/*
ID          DUO_DUO     ID          STUFF
----------- ----------- ----------- --------------------------------------------------
1           1           1           foo
2           2           2           bar

*/

Attachment: testcase.log
Description: Binary data

#!/usr/bin/python
import sqlalchemy as sa
import sqlalchemy.orm
import sqlalchemy.ext.declarative
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship, backref
import logging
logging.basicConfig(filename='testcase.log',level=logging.DEBUG)
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
logging.getLogger('sqlalchemy.dialects').setLevel(logging.DEBUG)
logging.getLogger('sqlalchemy.pool').setLevel(logging.DEBUG)
logging.getLogger('sqlalchemy.orm').setLevel(logging.DEBUG)

cs = "mssql+pyodbc://sa:password@127.0.0.1\sqlexpress/TestDataBase?port=1433"

Base = sqlalchemy.ext.declarative.declarative_base()
engine = sa.create_engine(cs)
Session = sqlalchemy.orm.sessionmaker(bind=engine)
session = Session()



class Uno(Base):
    __tablename__ = 'UNO'
    __table_args__ = {
        'autoload':True,
        'autoload_with':engine
        }
    duos = relationship("DuoDuo",backref=backref("duos"))

    def __repr__(self):
        return '<uno {}>'.format(self.ID)

class DuoDuo(Base):
    __tablename__ = 'DUO_DUO'

    __table_args__ = {
        'autoload':True,
        'autoload_with':engine
        }
    def __repr__(self):
        return '<DuoDuo {},{}>'.format(self.ID, self.STUFF)


def main():
    try:
            print session.query(Uno, Uno.duos).all()
    except:
            logging.exception('Logging the Exception')


if __name__ == '__main__': main()

Reply via email to