I'm trying to use the primaryjoin/foreign_keys parameters (http://
www.sqlalchemy.org/docs/05/mappers.html#specifying-foreign-keys) to
specify a relation between tables that don't have explicit foreign
keys but apparently it's not enough for join() to figure it out:
from sqlalchemy.orm import join, relation
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String(50))
class Address(Base):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
email = Column(String(50))
user_id = Column(Integer)
user = relation(User, primaryjoin=User.id==user_id,
foreign_keys=user_id)
# this works
>>> print join(User, Address, Address.user)
users JOIN addresses ON users.id = addresses.user_id
# this doesn't
>>> print join(User, Address)
Traceback (most recent call last):
...
sqlalchemy.exc.ArgumentError: Can't find any foreign key relationships
between 'users' and 'addresses'
Why doesn't join() figure out the join condition, and is there a way
to make it work without having to pass it explicitly every time ?
George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---