-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[要望]BlogControllerにイベント beforeQueryParamsを追加したい #3634
Comments
beforeFindとBcBlog.BlogPosts.beforeFindで取得できる情報が異なりますね。 baserのイベント周りの調整が必要かもしれません。
|
下記コミットで変更となっているのが原因ようですね。5.0の最新だとすでにこのコミットが入っています。 また、こちらのプルリクにもコメントを書きましたが、afterFindで書き換えるというのでもいいかもしれません。 ただ、Cake本体側のイベントに渡すパラメーターが元々こちらなので、こちらに合わせた方がいいかもですね。
|
afterFindがなかったからか。ということは、beforeFindが2発発動されてしまう可能性が高い?(要調査) |
@seto1 調査しましたが、
AppTableのbeforeFindを削除することを検討したいですね、、、 |
@katokaisya 取り急ぎ参照を入れておきます。 |
現時点で分かっていること where の第2引数に true を設定すると上書きとなる
元々のwhere条件を取得する
が、実態である つまり、既存の条件を参照しつつ、一部の条件だけを書き換えて、 afterFindの呼び出し順が想定と違った
これらを踏まえて仕様の再検討が必要 |
課題は3点 検索パラメーターの一部書き換えをどうやってやるか加藤さんの提案のとおり、Queryオブジェクト作成前のタイミングで書き換えさせる方が良さそう。 beforeFindの重複AppTableのbeforeFindは削除した方が混乱をうまない afterFindの呼び出し順AppTableのbeforeFind を削除した場合、順番が逆となる。イベント名称を違うものに変更した方がよいかも
|
解消したいですね。それで beforeFind と BcBlog.BlogPosts.beforeFind の挙動が揃うのであれば特に。
既存のイベントで対応できるのに新しくイベントを増やしたくないという気持ちはありますね。 まあ、無理矢理感はあります。
|
サービスクラスのメソッドが呼び出される際に毎回発火するイベントがあるなら使いやすそうですけど難しそうですね。 getIndexに個別でイベントを追加すると、サービスクラスの他の関数にもイベントを追加したくなってコード量が大幅に増えてしまいそうです。 もしくは、せっかくサービスクラスにInterfaceを使っているので、任意のクラスに変更できるようになればイベント以上に自由度が上がりますね。 |
■サービスクラスの切り替え ■where条件の上書き ■Queryを一度配列に変換して条件を変更しやすくする 試作
|
@seto1 リセットしないでも下記のコードでいけました。汎用的ではないですが if ($event->getData(0) instanceof \Cake\ORM\Query\SelectQuery) {
$where = $event->getData(0)->clause('where');
/** @var QueryExpression $where */
$where->iterateParts(function($part, $key) {
if ($part instanceof ComparisonExpression) {
if ($part->getField() === 'BlogPosts.blog_content_id') {
$part->setValue([1, 2]);
}
}
});
} |
概要
baserCMS4系では、BlogPost.beforeFindでconditionsを上書きできたが、
baserCMS5系では BcBlog.BlogPosts.beforeFindでは、すでにクエリが出来上がっており、
クエリの追加しかできないため、上書きできるように、クエリ発行前のイベントがほしいです。
【例】blog_content_id を変更したい、など
baserCMS version : 5.1.x
TODO
The text was updated successfully, but these errors were encountered: