Using the collection_class=set is only going to work if I try to add the 
same pest multiple times into pestList isn't it?
My situation is more along the lines that the pest table already has the 
pest, and the pesticide I want to add also will have that pest, so I want 
the entries in the pest_to_pesticide created. What currently happens is an 
IntegrityError is thrown complaining that there is a duplicate pest entry.

On Wednesday, April 24, 2013 1:24:59 PM UTC-4, Michael Bayer wrote:
>
> pesttopesticide is maintained by relationship() as the "secondary" table, 
> but the expectation is that rows in this table will be unique.  if you are 
> appending duplicate entries to "pestList" or "pesticide" you may want to 
> use collection_class=set to maintain uniqueness in the collection.
>
>
> On Apr 24, 2013, at 12:51 PM, dan <d...@inlet.geol.sc.edu <javascript:>> 
> wrote:
>
> 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) 
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+...@googlegroups.com <javascript:>.
> To post to this group, send email to sqlal...@googlegroups.com<javascript:>
> .
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to