遇到一个非常严重的问题时,我以为我已经遇到了系统问题,我有一个名为lpm_case的表,该表由lpm_bill引用,而lpm_bill则由lpm_payment引用,如下所示:
db.define_table('lpm_case',
Field('title', 'string', requires=IS_NOT_EMPTY()),
Field('case_number'),
Field('practice_area', requires=IS_IN_SET(practice_area, multiple=False), default=practice_area[0]),
Field('opening_date', 'date', requires=IS_DATE(format=T('%Y-%m-%d')), default=datetime.now()),
Field('case_description', 'text', requires=IS_NOT_EMPTY()),
Field('case_stage', requires=(IS_IN_SET(stage, multiple=False)), default='Investigation'),
Field('case_status', requires=IS_IN_SET(status, multiple=False), default=status[0]),
Field('judge_name'),
Field('privacy', requires=(IS_IN_SET(('only me', 'public'))),
widget=SQLFORM.widgets.radio.widget),
auth.signature)
db.define_table('lpm_bill',
Field('matter_case', 'references lpm_case'),
Field('bill_schedule', requires=IS_IN_SET(BILLING_SCHEDULES, multiple=False), default=BILLING_SCHEDULES[0]),
Field('bill_scale', requires=IS_IN_SET(BILLING_SCALE, multiple=False), default=BILLING_SCALE[0]),
Field('service_name', requires=IS_NOT_EMPTY()),
Field('service_description', 'text', requires=IS_NOT_EMPTY()),
Field('service_charge', 'double', requires=IS_NOT_EMPTY(), default=0),
Field('fees_paid', 'double', default=0),
Field('status', requires=IS_IN_SET(BILL_STATUS, multiple=False), default=BILL_STATUS[0]),
Field('service_tax', 'double', requires=(IS_NOT_EMPTY()), default=0),
auth.signature)
db.define_table('lpm_payment',
Field('service_bill', 'references lpm_service_bill', writable=False, readable=False),
Field('payment_title'),
Field('payment_method', requires=IS_IN_SET(PAYMENT_METHOD, multiple=False), default=PAYMENT_METHOD[0]),
Field('trans_rec_num', requires=IS_NOT_EMPTY()),
Field('payment_date', 'date', requires=IS_DATE(format=T('%Y-%m-%d')), default=datetime.now()),
Field('payment_amount', 'double', requires=(IS_NOT_EMPTY()), default=0),
auth.signature)
现在,我在视图中的某处有一个ajax回调,该回调使我可以从lpm_case删除给定记录,它仅将记录id解析为执行删除操作的控制器函数,这样就可以正常工作。该记录从lpm_case表中删除,下面是控制器功能
def delete_case():
var = request.get_vars
id = var.id
if var:
db(db.lpm_case.id == id).delete()
redirect(URL('list_cases'))
问题是CASCADING不会发生,我希望默认情况下也会删除lpm_bill中附加到我已从lpm_case删除的记录的所有其他记录,就像明智地将lpm_payment中的所有记录附加到lpm_bill的已删除记录一样。但这不会发生,从而导致引用中断。因此,当我从终端转到postgres并直接运行SQL语句以删除lpm_case记录时,我得到了一些凭单,但CASCADING至少可以运行。有人能帮我解决这个使我无法按时完成的简单事情吗? 谢谢