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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---