> at the moment a relationship() can't reliably be used as an expression in 
> query(), there's a ticket to enhance this functionality at 
> http://www.sqlalchemy.org/trac/ticket/2846.  Based on what it seems like 
> the intent here is, I think you want: 
>
> session.query(Uno, DuoDuo).join(Uno.duos).all() 
>
> Yes, this works. Thanks.
I was trying the other form because that was what came first in your pycon 
tutorial (which was great. Especially sliderepl.)
 

> Also you probably want to specify table name as lowercase "uno", the 
> uppercase "UNO" indicates to SQLAlchemy a case-sensitive name which will be 
> quoted as uppercase exactly, unless the schema were actually created with 
> quoted uppercase names. 
>

I do, but it doesn't work:

NoForeignKeysError: Could not determine join condition between parent/child 
> tables on relationship Uno.duos - there are no foreign keys linking these 
> tables.  Ensure that referencing columns are associated with a ForeignKey 
> or ForeignKeyConstraint, or specify a 'primaryjoin' expression.



(The database is not case sensitive - so that can be discounted.) The 
reflected foreign key looks the same regardless of if the tablename is in 
upper or lower case (on either table - I tried all 4 combinations): I don't 
know if that's relevant?

>>> Uno.__table__.foreign_keys
> set([ForeignKey(u'DUO_DUO.ID')])


Then with both __tablename__ as the lower case version:


>>> DuoDuo.__tablename__
'duo_duo'


>>> DuoDuo.__table__
Table('duo_duo', MetaData(bind=None), Column(u'ID', INTEGER(), 
table=<duo_duo>, primary_key=True, nullable=False, 
default=Sequence(u'ID_identity', start=1, increment=1, 
metadata=MetaData(bind=None))), Column(u'STUFF', NVARCHAR(length=50), 
table=<duo_duo>), schema=None)


>>> Uno.metadata.tables.keys()
['duo_duo', u'DUO_DUO', 'uno']

>>> Uno.metadata.tables['duo_duo'] == Uno.metadata.tables['DUO_DUO']
False


>>> pprint(Uno.metadata.tables)
immutabledict({'duo_duo': Table('duo_duo', MetaData(bind=None), 
Column(u'ID', INTEGER(), table=<duo_duo>, primary_key=True, nullable=False, 
default=Sequence(u'ID_identity', start=1, increment=1, 
metadata=MetaData(bind=None))), Column(u'STUFF', NVARCHAR(length=50), 
table=<duo_duo>), schema=None), u'DUO_DUO': Table(u'DUO_DUO', 
MetaData(bind=None), Column(u'ID', INTEGER(), table=<DUO_DUO>, 
primary_key=True, nullable=False, default=Sequence(u'ID_identity', start=1, 
increment=1, metadata=MetaData(bind=None))), Column(u'STUFF', 
NVARCHAR(length=50), table=<DUO_DUO>), schema=None), 'uno': Table('uno', 
MetaData(bind=None), Column(u'ID', INTEGER(), table=<uno>, 
primary_key=True, nullable=False, default=Sequence(u'ID_identity', start=1, 
increment=1, metadata=MetaData(bind=None))), Column(u'DUO_DUO',INTEGER(), 
ForeignKey(u'DUO_DUO.ID'), table=<uno>, nullable=False), schema=None)})

-- 
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.

Reply via email to