On Dec 4, 2012, at 2:30 PM, Diego Woitasen wrote: > Hi, > I have the following tables: > > rcpt_group_asoc = Table("mailing_rcptgroup_rcpts", Base.metadata, > Column('rcpt_id', Integer, ForeignKey('mailing_rcpt.id')), > Column('rcptgroup_id', Integer, > ForeignKey('mailing_rcptgroup.id'))) > > > class Rcpt(Base): > __tablename__ = 'mailing_rcpt' > > id = Column(Integer, primary_key=True) > > mail_addr = Column(String(128+256), nullable=False) > rcpt_groups = relationship("RcptGroup", secondary=rcpt_group_asoc, > backref="rcpts") > > class RcptGroup(Base): > __tablename__ = 'mailing_rcptgroup' > > id = Column(Integer, primary_key=True) > name = Column(String(64), nullable=False, unique=True) > > I'm trying to do: > > > group = db.RcptGroup.__table__ > rcpt = db.Rcpt.__table__ > print group.join(rcpt) > > And got: > > ArgumentError: Can't find any foreign key relationships between > 'mailing_rcptgroup' and 'mailing_rcpt'.
the join() method of Table (which is what RcptGroup.__table__ is) is part of SQLAlchemy Core and has no awareness of the relationship() construct and therefore no implicit awareness of the rcpt_group_assoc table, if not provided explicitly. If using a pure Core approach, you'd need to join explicitly, group.join(rcpt_group_assoc).join(rcpt). Alternatively, you can use the orm.join() construct and provide the relationship() bound attribute: from sqlalchemy.orm import join j = join(RcptGroup.rcpts) though typically sticking with query.join() is the simplest approach. I never have a need to use the standalone join() function when querying with the ORM. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.