'Test archiving of a record which is referenced by
other records'

def testArchiveCascade(self):

    assertEqual = self.assertEqual
    assertNotEqual = self.assertNotEqual
    assertTrue = self.assertTrue
    s3db = current.s3db
    s3db.clear_config('del_master', 'super_entity')
    master_id = self.master_id
    s3db.define_table('del_component', Field('del_master_id', s3db.del_master, ondelete='CASCADE'), *s3_meta_fields())
    component = s3db['del_component']
    s3db.add_components('del_master', del_component='del_master_id')
    try:
        component_id = component.insert(del_master_id=master_id)
        component_record = component[component_id]
        assertNotEqual(component_record, None)
        current.db.commit()
        resource = s3db.resource('del_master', id=master_id)
        success = resource.delete()
        assertEqual(success, 1)
        assertEqual(resource.error, None)
        table = s3db.del_master
        record = table[master_id]
        assertTrue(record.deleted)
        component_record = component[component_id]
        assertTrue(component_record.deleted)
        assertEqual(component_record.del_master_id, None)
        assertEqual(self.master_deleted, master_id)
        assertEqual(self.super_deleted, 0)
        assertEqual(self.component_deleted, component_id)
    finally:
        component.drop()
        del current.model.components['del_master']['component']
