Thanks for the self.delete() answer. I'll still need to session.flush()
beforehand in order to make sure that any pending objects become persistent,
right?

jor

On Wed, Aug 27, 2008 at 4:27 AM, Gaetan de Menten <[EMAIL PROTECTED]>wrote:

>
>
>
> On Tue, Aug 26, 2008 at 9:04 PM, Jor Bratko <[EMAIL PROTECTED]> wrote:
> >
> > I'm writing an application using Turbogears and I'm migrating it from
> > SQLObject to Elixir/SQLAlchemy. I have declared an Item class which
> > has an amount. I want the Item to be deleted if the amount goes to 0.
> >
> > class Item(Entity):
> >    id = Field(Integer, primary_key=True)
> >    itemType = ManyToOne('ItemType')
> >    amount = Field(Integer)
> >    quality = Field(Integer)
> >    ...a bunch of ManyToOne relationships
> >
> >   def SubtractAmount(self, amount):
> >       self.amount -= amount
> >       if self.amount == 0:
> >           self = None # was self.destroySelf() using SQLObject
> >       return
>
> Assigning self to None is dubious at best. To delete an object (remove
> its row from the database), you should rather use self.delete() (which
> is a shortcut of session.delete(self)).
>
> --
> Gaƫtan de Menten
> http://openhex.org
>
> >
>
>
> --
> If this email is spam, report it here:
>
> http://www.onlymyemail.com/view/?action=reportSpam&Id=NDA2MDQ6NzI5MDUzNjA2OmpvcmJyYXRrb0BzcGVha2Vhc3kubmV0
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to