Hi,
[apologies if this is double posted, having some issues shifting
google groups to gmail]
I have a problem with an adjacency list table, my knowledge of DB
design is flakey at best so please bear with me in terminology and my
attempt at an explanation.
I have a table/class/mapping as follows (the DB is sqlite3):
invoices_table = Table('invoices', metadata,
Column('id', Integer, primary_key=True),
Column('active', Boolean),
Column('invoice_no', Integer),
Column('project_id', Integer, ForeignKey('projects.id')),
Column('invoice_id', Integer, ForeignKey('invoices.id')),
Column('name',String),
Column('creation_date',DateTime),
Column('due_date',DateTime),
Column('invoiced', Boolean),
Column('invoiced_date',DateTime),
Column('invoice_paid',Boolean),
Column('invoice_paid_date',DateTime),
Column('invoice_split',Boolean),
Column('invoice_split_amount', Numeric),
Column('override_day_rate',Boolean),
Column('day_rate', Integer),
Column('is_quote',Boolean),
Column('quote_no', Integer),
Column('ballpark',Boolean),
Column('user_id', String, ForeignKey('users.id')),
Column('payment_schedule',String)
)
class ArkInvoice(object):
def __init__(self):
self.creation_date=datetime.datetime.now()
self.invoice_split=False
self.is_quote=True
self.active=True
self.invoiced_date=datetime.datetime(0001,01,01)
self.ballpark=False
self.invoice_no=None
mapper(ArkInvoice, invoices_table, properties={
'entries': relation(ArkInvoiceEntry,
secondary=invoice_entries_primary_table, backref='invoice',
cascade="all, delete, delete-orphan"),
'user': relation(ArkUsers, backref='user'),
'child_invoices':relation(ArkInvoice,
backref=backref('parent_invoice',
remote_side=[invoices_table.c.id]),
cascade="all",
lazy=False,
join_depth=3)
})
The idea behind this is that invoices can have a hierarchy, and some
invoices are effectively parented under a parent invoice. This
parenting only ever needs to be one level deep.
The problem I'm having is child_invoices works fine for the parent
ArkInvoice object, however none of the children seem to receive a
backref, in so much as type(invoiceObject.parent_invoice) is a
'NoneType', yet I would expect it to return the parent arkInvoice
obhject.
I've pulled most of the above code from the sqlalchemy example on
Adjacency tables [http://www.sqlalchemy.org/docs/05/
mappers.html#adjacency-list-relationships], and can't see what I've
done wrong. Any pointers on this are much appreciated.
Many thanks,
Jules
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---