On Sep 24, 2008, at 5:19 PM, Doug Farrell wrote:
> class PressRoutingPress(Base): > '''This class defines the many-to-many join table between press > and press_routing. > ''' > __tablename__ = "press_routing_press" > __table_args__ = {'autoload' : True} > > press_id = Column(Integer, ForeignKey('press.id'), > primary_key=True) > press_routing_id = Column(Integer, ForeignKey('press_routing.id'), > primary_key=True) > > class PressRouting(Base): > '''This class defines the press_routing table information. > ''' > __tablename__ = "press_routing" > __table_args__ = {'autoload' : True} > > class Press(Base): > '''This class defines the press table information. > ''' > __tablename__ = "press" > __table_args__ = {'autoload' : True} > > # many to many Press<->PressRouting > press_routing = relation('PressRouting', > secondary=PressRoutingPress, > > primaryjoin=id==PressRoutingPress.press_id, > foreign_keys=[PressRoutingPress.press_id], > > secondaryjoin=PressRouting.id==PressRoutingPress.press_routing_id, > > foreign_keys=[PressRoutingPress.press_routing_id], > uselist=False) > #backref=backref('press')) > #viewonly=True) > > This all works till I try to instantiate an instance of a Press() > object, then I get the following exception: when you use the "secondary" argument on relation(), that should be a plain Table object and should not be mapped (i.e. there should be no separate class for it): press_routing_press = Table("press_routing_press", Base.metadata, Column("press_id", Integer, ForeignKey('press.id'), primary_key=True), Column("press_routing_id", Integer, ForeignKey('press_routing.id'),primary_key=True) ) class Press(Base): ... press_routing = relation("PressRouting", secondary=press_routing_press) no other arguments to relation() are needed. If you do want PressRoutingPress to be mapped, you use the association object pattern, which means you aren't using the "secondary" keyword. The non-declarative version is here: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_patterns_association --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---