I'm getting an SAWarning (0.6.4 and also 0.7b5dev) which has a message that confuses me, so I've duplicated the problem with a script: =================================================== from sqlalchemy import * from sqlalchemy.orm import *
engine = create_engine('sqlite:///', echo=True) metadata = MetaData(engine) session = sessionmaker(bind=engine)() # association table post_keywords = Table('post_keywords', metadata, Column('post_id', Integer, ForeignKey('posts.id')), Column('keyword_id', Integer, ForeignKey('keywords.id')) ) posts_table = Table('posts', metadata, Column('id', Integer, primary_key=True), Column('headline', String(255), nullable=False), Column('body', Text) ) keywords_table = Table('keywords', metadata, Column('id', Integer, primary_key=True), Column('keyword', String(50), nullable=False, unique=True) ) spotlights_table = Table('spotlights', metadata, Column('id', Integer, primary_key=True), Column('enddate', Date), Column('post_id', Integer, ForeignKey('posts.id')) ) class BlogPost(object): def __init__(self, headline, body): self.headline = headline self.body = body def __repr__(self): return "BlogPost(%r, %r, %r)" % (self.headline, self.body, self.author) class Keyword(object): def __init__(self, keyword): self.keyword = keyword class PostSpotLight(object): pass mapper(Keyword, keywords_table) mapper(BlogPost, posts_table, properties = {'keywords': relationship(Keyword, secondary=post_keywords, backref='posts')} ) mapper(PostSpotLight, spotlights_table, properties = {'postkeywords': relationship(Keyword, secondary=post_keywords, primaryjoin=spotlights_table.c.post_id==post_keywords.c.post_id)} ) metadata.create_all(engine) compile_mappers() ========================================================= Here is the warning: [...]/sqlalchemy-default/lib/sqlalchemy/orm/properties.py:900: SAWarning: No ForeignKey objects were present in secondary table 'post_keywords'. Assumed referenced foreign key columns 'post_keywords.keyword_id', 'post_keywords.post_id' for join condition 'spotlights.post_id = post_keywords.post_id' on relationship PostSpotLight.postkeywords eq_pairs = self._sync_pairs_from_join(self.primaryjoin, True) Why is the complaint that there are No ForeignKey objects were present in secondary table 'post_keywords', when clearly there are? ***Furthermore, if I pass the relationship this: foreign_keys=[post_keywords.c.post_id,post_keywords.c.keyword_id] then the warning goes away, but all I've done is specify the very foreign_keys that already exist.*** (I realize now I could also use an association proxy for the keywords via the post, but the question remains.) Thanks as always, Kent -- 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.