the code there doesn't seem to show anything that would result in any DELETEs 
emitted.   a DELETE here would only occur if you deassociated a TestDevice and 
a TestPartition by removing from the TestDevice.partitions collection or 
setting a TestPartition.device to None, and I don't see that.   All of the 
manipulations you're doing with part.partition_id have nothing to do with any 
of that, SQLAlchemy's relationships have no idea what you're doing with those, 
and overall it's a bad idea to mix the usage of "obj.foreign_key = <id>" along 
with direct manipulation of the relationship (where you say dev_part.device  = 
ndev) together.   SQLAlchemy's relationship management code knows nothing about 
any of those foreign key sets.  See 
http://docs.sqlalchemy.org/en/rel_0_9/faq.html#i-set-the-foo-id-attribute-on-my-instance-to-7-but-the-foo-attribute-is-still-none-shouldn-t-it-have-loaded-foo-with-id-7.







On Jul 21, 2014, at 2:55 AM, Bala Ramakrishnan <bal...@gmail.com> wrote:

> I had asked this question on Stack Overflow. The details are at this link:
> 
> http://stackoverflow.com/questions/24836816/updating-a-few-children-in-one-to-many-relationship-deletes-all-rows-and-adds-ne
> 
> The summary is I have a parent class A and a bidirectional one-to-many 
> relationship with class B. When I update the class B list for an instance of 
> A, the update may involve deleting some class B instances, updating some of 
> them, and adding new ones. However, I find that SqlAlchemy deletes all ROWS 
> of classB, and the inserts the necessary new rows. I would have expected 
> SqlAchemy to insert only new rows, not delete and add those rows that are 
> being updated. Do you know what is wrong with my code?
> 
> Thanks.
> 
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to