1

yii2 フレームワークでフィルター条件を追加したいのですが、この条件は次のリクエストを生成する必要があります。

select count(*) from v_ressource
where 
(
    (
        str_to_date('27/04/2016', '%d/%m/%Y')
        between str_to_date(erDateDebut, '%d/%m/%Y')
        and str_to_date(erDateFin, '%d/%m/%Y')
    )
    and erDateFin is not null
)
or
(
    (
        str_to_date('27/04/2016', '%d/%m/%Y') 
        between str_to_date(erDateDebut, '%d/%m/%Y') 
        and now()
    )
    and erDateFin is null
);

ご覧のとおり、「or」条件の中に「and」条件があります。

ModelSearch に次のコードがあります。

    $query
        ->andFilterWhere([
            'between',
            'str_to_date(\'' . $this->dateRecherche . '\', \'%d/%m/%Y %H:%i\')',
            new Expression('str_to_date(erDateDebut, \'%d/%m/%Y %H:%i\')'),
            new Expression('str_to_date(erDateFin, \'%d/%m/%Y %H:%i\')'),
        ])
        ->andFilterWhere([
            'not', ['erDateFin' => null],
        ]);

    $query
        ->orFilterWhere([
            'between',
            'str_to_date(\'' . $this->dateRecherche . '\', \'%d/%m/%Y %H:%i\')',
            new Expression('str_to_date(erDateDebut, \'%d/%m/%Y %H:%i\')'),
            new Expression('now()'),
        ])
        ->andFilterWhere([
            'is', 'erDateFin', null,
        ]);

null 条件と null ではない条件の両方が、生成されたリクエストに表示されず、「ネストされた」条件 (および または 条件の条件) がありません。

ご協力いただきありがとうございます

4

1 に答える 1