Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin
Yes, you need to delete everything manually that is referenced by anything that is to be deleted. No, you don't. .destroySelf() in SQLObject 0.7.2 was extended to automatically remove rows from the intermediate table. Does it work? Maybe I'm misunderstanding you but if a foreignkey points to an object that is deleted, the object that refers to the deleted object will not be: from sqlobject import * sqlhub.processConnection = connectionForURI( 'sqlite:/:memory:' ) class city( SQLObject ): buildings = MultipleJoin( 'building' ) class building( SQLObject ): city = ForeignKey( 'city' ) city.createTable( ) building.createTable( ) c = city( ) b1 = building( city=c ) b2 = building( city=c ) c.destroySelf( ) print building.select( ).count( ) print b1.city This will print 2 and then an SQLObjectNotFound exception will be raised so you need to manually delete all buildings that refer to a deleted city. I guess you had RelatedJoin in mind. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin
I have two simple SQLObject classes, WebTag and WebTopic that are related using a RelatedJoin: class WebTag(SQLObject): Name = StringCol( alternateID=True) Topics = RelatedJoin('WebTopic') class WebTopic(SQLObject): Name = StringCol( unique=True ) Format = StringCol( default=rst ) Title = StringCol( ) Subtitle = StringCol( default=None) Description = StringCol(default=None) Keywords = StringCol( default=None ) Author = StringCol( default=None ) DateTimePosted = DateTimeCol() DateTimeLastModified = DateTimeCol() UUID = StringCol() Content = StringCol( default=None ) Tags = RelatedJoin('WebTag') What is the appropriate way to delete an instance of a WebTopic or a WebTag so that RelatedJoin won't be broken? Right now I have a simple: WebTopic.delete(id_to_delete) or a WebTag.delete(id_to_delete) But I just started getting this error, so I must have missed something in the documentation: for a in WebTag.selectBy(Name='python'): ... print a.Name ... print a.Topics ... python Traceback (most recent call last): File stdin, line 3, in module File string, line 1, in lambda File /usr/lib/python2.5/site-packages/sqlobject/joins.py, line 207, in performJoin return self._applyOrderBy([self.otherClass.get(id, conn) for (id,) in ids if id is not None], self.otherClass) File /usr/lib/python2.5/site-packages/sqlobject/main.py, line 913, in get val._init(id, connection, selectResults) File /usr/lib/python2.5/site-packages/sqlobject/main.py, line 958, in _init raise SQLObjectNotFound, The object %s by the ID %s does not exist % (self.__class__.__name__, self.id) sqlobject.main.SQLObjectNotFound: The object WebTopic by the ID 12 does not exist Any help and suggestions would be appreciated. The db can be wiped and started over, because this is a little test system. Should I have dropped all references to the missing WebTopic instance from all WebTag instances? Yes, you need to delete everything manually that is referenced by anything that is to be deleted. A question to the experts: I usually do this by overloading destroySelf so that it loops over all references, is that a good idea? - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin
On 7/9/07, Oleg Broytmann [EMAIL PROTECTED] wrote: On Mon, Jul 09, 2007 at 12:09:25PM +0200, Daniel Nogradi wrote: Yes, you need to delete everything manually that is referenced by anything that is to be deleted. No, you don't. .destroySelf() in SQLObject 0.7.2 was extended to automatically remove rows from the intermediate table. Does it work? I switched to WebTag.get(tag_id_to_delete).destroySelf() and that works great in SQLObject-0.10dev_r2730 that the python easy_install upgrade leads to. Unfortunately Ubuntu Feisty Fawn is still stuck on 0.7.1 on their distro. Best Regards, Jon - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin
On Mon, Jul 09, 2007 at 08:28:51AM -0400, Jon R. Fox wrote: I switched to WebTag.get(tag_id_to_delete).destroySelf() This is equivalent to WebTag.delete(tag_id_to_delete) Oleg. -- Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss