[SQLObject] How do I update a many-to-many field?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Mike K. <mrm...@co...> - 2005-12-23 22:31:03
|
Given the following simple schema: class Author(SQLObject): lastName = StringCol(length=40, notNone=True) books = RelatedJoin('Book') # An author can write many books class Book(SQLObject): title = StringCol(length=100, notNone=True) authors = RelatedJoin('Author') # A book can have many authors I then make an Author and a Book: author = Author("Seuss") book = Book("The Cat In The Hat") Now I want to give the book an author: book.addAuthor(author) Hmm, let's make a new author and change the book's author: author = Author("Geissel") book.addAuthor(author) No, that's not right. I just gave that book two authors. What I want is some kind of update that will properly handle the deletion of the previous author and addition of the new author to the magic book-to-author table SQLObject created for me. Or at least a way for me to delete the previous author entries for this book, so I can add the new author entries. So what's the correct way to handle this type of CRUD? |