On Nov 22, 2010, at 9:57 AM, Catherine Devlin wrote: > 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'``
well thats a bug, the table is named incorrectly in the docs, and the target class should be in the docs too. > > 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. The #1 example ideally would be http://www.sqlalchemy.org/docs/orm/relationships.html#many-to-many . Linking to the tutorial is less than ideal since most examples build cumulatively on what was prior, so its not ideal as a "reference" document, even though the m2m at the bottom is a little more self contained. The section in declarative.html solved the issue of a pretty steady parade of users who were switching to declarative, and got confused over how to construct many to manys. It might be OK for declarative to link to the declarative example in many-to-many above, I'll consider more closely leaving the paragraph in declarative, but linking to the example in the main mapper docs, just to cut down on redundancy. > > 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. -- 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.