0

i have 2 Table

**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

i was able to insert query on table line_sale at the same time when i insert on Sale table with

 $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));

, i want to (delete , update ) the line_sale row with relation with sale table with one click , i mean when i delete the sale recorde with (id=2 "exemple") the line_sale with (id_sale=2) will be deleted automaticly , same thinck for update when i update (price , date ) for record with (id=2 "exemple") they will be updated automaticly on line_sale with (id_sale=2) i m using adapter for sql request and i use this function to get the Line_sale's for a specific 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

Loouu
  • 19
  • 7

1 Answers1

2

You can just use sql join or and like this:

DELETE FROM table1, table2 WHERE table1.id = (constant) AND table1.id = table2.id

Where constant is the id value that you want to delete form both table.

This has been answered in this question already by the way.

Community
  • 1
  • 1
Ace Munim
  • 325
  • 3
  • 18
  • thx but i m not asking for the sql request i m just asking how to apply it with adapter on my case – Loouu Aug 05 '13 at 17:43