Hello Michael, thank you for your answer. You are right that this behavior can be enforced by setting the viewonly attribute of the relation, and the others are not needed.
However, I do need to set it on both sides of the relation, or it does not work. But this not working might be triggered by another part of the model where there is a join between B and another table to form C. I will have to investigate further to get a definitive answer. Regards, Erik On Aug 10, 4:55 pm, Michael Bayer <[email protected]> wrote: > On Aug 10, 2011, at 6:56 AM, erikj wrote: > > > > > Hi, > > > I have a table and a view mapped to objects > > as such : > > > class A(object): > > mapped to a table > > with a primary key column id > > with a onetomany attribute list_of_b, being a relation > > to all rows of B with a_id == self.id > > > class B(object): > > mapped to a view > > with a column a_id being a reference to the id column of A > > > Since B is mapped to a view, no updates should happen on B. > > > So, in A, the list_of_b relation is configured with : > > > passive_updates = True, > > passive_deletes = 'all', > > viewonly = True, > > cascade = False > > > But whenever an object of A is deleted, sqlalchemy tries to update > > the a_id columns of all rows of B that were loaded in memory, which > > of course should not happen, since B is a view. > > You should only need "viewonly=True", which disables any persistence activity > on the relationship. A.list_of_bs would not participate in the flush > including no foreign key sync operations. > > A full test case demonstrating this behavior, using SQLite so that a "B" > table can be created with a non-enforcing FK, is attached. I thought > perhaps setting a backref might not propagate the "viewonly" but this also > works as expected. Check your configuration again to ensure it isn't doing > something else. > > viewonly_doesnt_affect_b.py > 1KViewDownload -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. 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.
