My use case is the following: each SalesItem requires a calcPriceList and a 
salesPriceList (of type PriceList) attached to it.
For that, SalesItem has two fields:
    calcpricelist_id = Column(BigInteger, ForeignKey(PriceList.id), 
nullable=False)
    salespricelist_id = Column(BigInteger, ForeignKey(PriceList.id), 
nullable=False)
It also has two relationships:
    calcPriceList = relationship(PriceList, primaryjoin=calcpricelist_id == 
PriceList.id, cascade='save-update,delete')
    salesPriceList = relationship(PriceList, primaryjoin=salespricelist_id 
== PriceList.id, cascade='save-update')

Now I have a problem -- I want to create a new SalesItem. I want to 
minimize the hassle so I set up a before_insert mapper listener (and 
verified it's being called) that attaches transient PriceList instances to 
said relationships.
What I expected the session to do during flush is to insert these two 
PriceLists into the database, fill in the calcpricelist_id and 
salespricelist_id fields on SalesItem before attempting to insert the 
SalesItem itself.
This is however not happening and it's trying to insert the SalesItem 
first, resulting in an IntegrityError.

Is what I am trying to do wrong? Should I just give up trying to do this in 
an event listener?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/dUchvgtL1mkJ.
To post to this group, send email to sqlalchemy@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.

Reply via email to