[orm-devel] orm/dbclass.py typo and a question on one2many deletions
Eric Walstad
orm-devel@mailman.tux4web.de
Mon, 06 Jan 2003 17:48:51 -0800
At around line 228 in orm/dbclass.py:
def invalidate(self, name):
"""
Reset the attribite NAME so it will be read from the db next
time it's accessed. Only works for Relationships.
"""
if self._data.has_key(name) and \
isinstance(self.columns[name], relationships.relationship):
del self._data[name]
seld._data[name] = self.columns[name].column()
---------------^
should be self._data[name] = self.columns[name].column()
Also, I'm having some trouble figuring out how to deal with a one2many
relationship. I've got:
invoices (one)
invoice_line_items (many)
and I'm trying to delete an invoice_line_item from both the database and
the invoice dbclass object. The invoice_line_item is getting deleted
from the db, as expected, but not from the invoice.invoice_line_item list:
>>> for li in invoice.invoice_line_items:
... print li.oid()
...
29761419
29928975
29928976
>>> invoice.invoice_line_items[0].oid()
29761419
>>> invoice.invoice_line_items[0].delete()
============================================================
DELETE FROM invoice_line_items WHERE oid=29761419
============================================================
>>> ds.commit()
>>> for li in invoice.invoice_line_items:
... print li.oid()
...
29761419
29928975
29928976
>>>
I'd like the second loop to result in:
29928975
29928976
so that the .delete()ed invoice_line_item is also deleted from the
invoice list.
What is the standard procedure for doing such a thing?
Thanks! I hope you all had a pleasant holiday season.
Best,
Eric.
PS, here's my dbclass Table definitions:
class invoice_line_items(dbclass):
columns = { "id" :integer(),
"quantity" :varchar(),
"description" :varchar(),
"unit_price" :varchar(),
"item_date" :timestamp(),
"invoices_id" :integer()}
class invoices(dbclass):
columns = { "id" :integer(),
"invoice_date" :timestamp(),
"date_paid" :timestamp(),
"void" :boolean(),
"tax_rate" :varchar(),
"project_id" :integer(),
"remarks" :varchar(),
"payment_memo" :text(),
"invoice_line_items":one2many(invoice_line_items,
"invoices_id")}