Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin

2007-07-10 Thread Daniel Nogradi
> > 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:
>
>This has nothing with RelatedJoin. You case is much simpler to fix:
>
>
> > class building( SQLObject ):
> > city = ForeignKey( 'city' )
>
> city = ForeignKey( 'city' , cascade=True)

Thanks a lot, this is really great, I didn't know about the cascade
option, I was always overriding destroySelf. And of course you are
right, this is specific to MultipleJoin and the OP was talking about
RelatedJoin.

Thanks again.

-
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

2007-07-10 Thread Oleg Broytmann
On Tue, Jul 10, 2007 at 11:06:17AM +0200, Daniel Nogradi wrote:
> 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:

   This has nothing with RelatedJoin. You case is much simpler to fix:

> class building( SQLObject ):
> city = ForeignKey( 'city' )

city = ForeignKey( 'city' , cascade=True)

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


Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin

2007-07-10 Thread Daniel Nogradi
> > 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

2007-07-09 Thread Jon R. Fox
Excellent.

I tried changing syntax first, which didn't work, and then realized
that the version of sqlobject installed on this machine was stale. I'm
glad they are equivalent, because I enjoy terseness.

Filing an upgrade bugrequest for the ubuntu people is now on my todo
list. With the popularity of  turbogears, a lot of folks are going to
try a related join and then reach this problem.

-- Jon

On 7/9/07, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> 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
>


-- 
Dr. Jon R. Fox
Applied Physicist and Technologist
[EMAIL PROTECTED]
http://www.drfox.com
1-973-494-0370

-
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

2007-07-09 Thread Oleg Broytmann
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


Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin

2007-07-09 Thread Jon R. Fox
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

2007-07-09 Thread Oleg Broytmann
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?

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


Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin

2007-07-09 Thread Oleg Broytmann
On Sat, Jul 07, 2007 at 02:34:11PM -0400, Jon R. Fox wrote:
> What is the appropriate way to delete an instance of a WebTopic or a
> WebTag so that RelatedJoin won't be broken?

   .destroySelf() in SQLObject 0.7.2 was extended to automatical remove
rows from the intermediate table. Does it work?

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


Re: [SQLObject] The proper way to delete an instance of an SQLObject that is linked as a RelatedJoin

2007-07-09 Thread Daniel Nogradi
> 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 "", line 3, in 
>   File "", line 1, in 
>   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