<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;

class CampQstQ extends QueryBuilder
{
    protected string $table = 'CAMP_QST_Q with (nolock)';
    protected string $primaryKey = 'ID_QUEST';
    
    // TODO : factorize with other QueryBuilder
    // Cascade delete MEMOS
    public function delete($id)
    {
        $inTrans = $this->pdo->inTransaction();
        if (!$inTrans) {
            $this->pdo->beginTransaction();
        }
        
        $param = [];
        $this->pdo->prepare(
            "DELETE MEMOS FROM MEMOS 
            JOIN CAMP_QST_Q ON CAMP_QST_Q.NM_COM = MEMOS.NODEMEMO
            WHERE " . $this->getDeleteWhere($id, $param)
        )
        ->execute($param);

        $res = parent::delete($id);
        
        if (!$inTrans) {
            $this->pdo->commit();
        }

        return $res;
    }
}
