Thread: [SQLObject] One-to-Many relations, foreign keys, deleting elements
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oliver A. <oli...@gm...> - 2005-11-04 06:58:04
|
Hi! First of all let me state, that I don't want to be the heretic or troll of the day. :) I am currently developing a quite large application using SQLObject as its ORM. In my model I have some one-to-many relations like that class Agency(SQLObject): name =3D UnicodeCol(length=3D64) departments =3D MultipleJoin("Department") class Department(SQLObject): name =3D UnicodeCol(length=3D64) agency =3D ForeignKey("Agency") I am using a MySQL database as the underlying SQL database. Yesterday, I wrote a little admin interface for the whole stuff to ease my testing a little bit. Sadly, a co-worker stumbled across it, deleted an agency and was confused cause the departments weren't removed. Okay, I thought to myself, I don't use InnoDB, so it is okay. Now, the same co-worker is Rails oder better said ActiveRecord addict and asked, if my OR= M can't handle it. Well, he defined the agency to department relation using this line "has_man= y :ressorts, :dependent =3D> true" and was finished. Is there something simil= ar in SQLObject? Or is something planned, that does something similar? Hopefully, I don't bother you with this question, but I am digging a little more into SQLObject. :) Best regards, Oliver -- Oliver Andrich <oli...@gm...> --- http://roughbook.de/ |
From: Ian B. <ia...@co...> - 2005-11-04 07:38:03
|
Oliver Andrich wrote: > Hi! > > First of all let me state, that I don't want to be the heretic or troll > of the day. :) > > I am currently developing a quite large application using SQLObject as > its ORM. In my model I have some one-to-many relations like that > > class Agency(SQLObject): > name = UnicodeCol(length=64) > departments = MultipleJoin("Department") > > class Department(SQLObject): > name = UnicodeCol(length=64) > agency = ForeignKey("Agency") > > I am using a MySQL database as the underlying SQL database. > > Yesterday, I wrote a little admin interface for the whole stuff to ease > my testing a little bit. Sadly, a co-worker stumbled across it, deleted > an agency and was confused cause the departments weren't removed. Okay, > I thought to myself, I don't use InnoDB, so it is okay. Now, the same > co-worker is Rails oder better said ActiveRecord addict and asked, if my > ORM can't handle it. agency = ForeignKey('Agency', cascade=True) -- Ian Bicking | ia...@co... | http://blog.ianbicking.org |
From: Oliver A. <oli...@gm...> - 2005-11-04 07:48:25
|
2005/11/4, Ian Bicking <ia...@co...>: > > agency =3D ForeignKey('Agency', cascade=3DTrue) Thank you very much. Works fine for me and should be mentioned in the documentation. :) And you saved my day ... Bye, Oliver -- Oliver Andrich <oli...@gm...> --- http://roughbook.de/ |