When I went looking for docs to remind myself how to build a many-to-many
relationship, the first doc I found at
http://www.sqlalchemy.org/docs/orm/extensions/declarative.html

keywords = Table(
    'keywords', Base.metadata,
    Column('author_id', Integer, ForeignKey('authors.id')),
    Column('keyword_id', Integer, ForeignKey('keywords.id'))
    )

class Author(Base):
    __tablename__ = 'authors'
    id = Column(Integer, primary_key=True)
    keywords = relationship("Keyword", secondary=keywords)

... confused me completely, because I couldn't tell whether ``keywords`` was
the association table?  (Which seemed to be implied by
``secondary=keywords``).  And ``keywords`` has a foreign key
(``keyword_id``) which points to ``keywords.id``, a column that... doesn't
exist?  Trying to run it threw ``sqlalchemy.exc.NoReferencedColumnError:
Could not create ForeignKey 'keywords.id' on table 'keywords': table
'keywords' has no column named 'id'``

Anyway, I suggest that it would be much less confusing to just refer to the
ORM tutorial example, "Building a Many To Many Relationship" at
http://www.sqlalchemy.org/docs/orm/tutorial.html, which I think is much more
clear but which unfortunately only shows up at position #14 in the search
results of a "many-to-many" search.

Thanks!

-- 
- Catherine
http://catherinedevlin.blogspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to