我有2个表
**Table sale :**
id_sale int
id_projet int
price float
date date
**Table sale_ligne:**
id_sale_ligne int
id_sale int FK_SALE
id_projet int
price float
date date
当我使用
在Sale表上插入时,我能够同时在表line_sale上插入查询 $this->dbAdapter->query('INSERT INTO sale (price, date) VALUES (?, ?)', array('price', 'date'));
$salesId = $this->dbAdapter->getDriver()->getLastGeneratedValue();
$this->dbAdapter->query('INSERT INTO sale_ligne (price, date, id_sale) VALUES (?,?,?)',array('price', 'date', $salesId));
,我想(删除,更新)与销售表关联的line_sale行,只需点击一下,我的意思是当我删除销售记录(id = 2“exemple”)时,line_sale(id_sale = 2)将自动删除,同样的更新更新,当我更新(价格,日期)记录(id = 2“例证”)时,它们将在line_sale上自动更新(id_sale = 2) 我使用适配器进行sql请求,我使用此函数获取特定销售的Line_sale
public function getLigneVenteByVente($id)
{
$result = $this->select(function (Select $select) use ($id){
$select->where(array('id_sale'=>$id));
$select->join('sale', ' ligne_sale.id_sale=sale.id ');
});
return $result;
}
THX
答案 0 :(得分:2)
你可以使用sql join或像这样:
DELETE FROM table1, table2 WHERE table1.id = (constant) AND table1.id = table2.id
其中,constant是要从两个表中删除的id值。
顺便提一下this question已经回答了这个问题。