On Feb 12, 2008, at 9:41 AM, Donovan Kolbly wrote:
> > I am trying to go through the mapping tutorial in 0.4.2p3 for > association objects. I get an error about "Could not assemble any > primary key columns for mapped table 'association'" when attempting to > map the association table itself. This is straight out of the Mapping > Configuration docs that comes with the distribution... > > Any thoughts on where things are going awry? > > Here's my complete code: > > from sqlalchemy import create_engine, \ > Table, Column, Integer, String, \ > MetaData, ForeignKey > from sqlalchemy.orm import relation, sessionmaker, mapper > > engine = create_engine('sqlite:///:memory:', echo=True) > > metadata = MetaData(); > > left_table = Table('left', metadata, > Column('id', Integer, primary_key=True)) > > right_table = Table('right', metadata, > Column('id', Integer, primary_key=True)) > > association_table = Table('association', metadata, > Column('left_id', Integer, ForeignKey('left.id')), > Column('right_id', Integer, ForeignKey('right.id')), > Column('data', String(50)) > ) > > class Parent(object): pass > class Association(object): pass > class Child(object): pass > > mapper( Parent, left_table, properties={ > 'children':relation(Association) > }) > > mapper( Association, association_table, properties={ > 'child':relation(Child) # <--- chokes here > }) > > mapper( Child, right_table) > > metadata.create_all( engine ) > the association_table itself has no primary key columns, so you have to tell the mapper which columns it should consider to be the primary key: mapper(Association, association_table, properties={...}, primary_key=[association_table.c.left_id, association_table.c.right_id]) Ill update the docs right now. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---