dan
unread,Apr 24, 2013, 12:51:49 PM4/24/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sqlal...@googlegroups.com
I've got a many to many relationship with the association table. The issue I am running into is that a given pesticide entry may have a pest or pests already in the pest table. I don't want to add the pest since it will be a duplicate, however I still want the association of that pest to the pesticide done.
I've looked at the Unique Object wiki, however I am not sure that solves my issue. Is there a way that SQLAlchemy can handle this, or do I need to manually build the entries in the PestToPesticide association table?
Thanks!
Dan
PestToPesticide = Table('pest_to_pesticide', Base.metadata,
Column('pesticide_id', Integer, ForeignKey('pesticide.row_id')),
Column('pest_id', Integer, ForeignKey('pest.row_id'))
)
class Pesticide(Base):
__tablename__ = 'pesticide'
row_id = Column(Integer,primary_key=True)
name = Column(String(64), unique=True)
pestList =relationship("Pest", secondary=PestToPesticide, backref="pesticide")
class Pest(object):
row_id = Column(Integer,primary_key=True)
name = Column(String(), unique=True)