Hello para master yii, saya sedang membuat system invoice dengan relasi 3 table (produk, invoice, invoice_detail)
(1.) produk (id_produk, Nama_produk, harga)
(2.) invoice (id_invoice, tgl_invoice, total)
(3.) invoice_detail (id_detail, id_invoice, id_produk, qty, total)
semua relasi dibagian inputnya sudah oke semua, masalahnya pada bagian delete jika saya mendelete isi table invoice form PK(id_invoice) tetapi invoice_detailnya tidak mau terhapus.
setelah saya cari-cari dengan cara afterdelete dan beforedelete bagaimana saya dapat menerapkan after dan before pada script saya ya?.
berikut potongan scripnya
invoiceController:
function actionDelete($id)
{
$data= new Invoice;
$model= $data->findByPK($id)->delete();
}
invoicedetail (model):
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'ProdukRel' => array(self::BELONGS_TO,'Produk','id_produk'),
'InvoiceRel' => array(self::BELONGS_TO,'Invoice','id_invoice'),
);
}
berikut saya lampirkan contohnya : saya mendelete id_invoice PK (4).