ダイナミックファインダーメソッドを使いたいと思います。私はthe documentation$this->Users->findByUsername
で見ました。私の問題は、私の列名がpost_id
だから、アンダースコアがダイナミックファインダ関数の名前にどのように影響するか分かりません。ここで私はこれまで試したものであり、ここでは文脈についてCakePHP 3ダイナミックファインダー(アンダースコア付き)
findByPost_id($post_id)
findByPost_Id($post_id)
findByPost_ID($post_id)
findByPostId($post_id)
ワーキングように見えることはできませんすることは、私はそれがクエリを出力し$question
ログインすると自分のコードが
//VotesTable.php
public function afterSaveCommit($event, $entity, $options) {
if ($entity->vote_type_id == self::favorite) {
$qt = TableRegistry::get('questions');
$question = $qt->findByPostId($entity->post_id);
$question->favorite_count = $question->favorite_count + 1;
if (! $qt->save($question)) {
throw new \Exception("Unable to update favorite count", 500);
}
}
}
次のようになりますオブジェクトではなく、クエリを実行できません。あなたの列名がある場合、それはWHERE 'questions'.'post_id' = :c0
ここにコード全体を投稿してください。ダイナミックローダーを使うときは 'findByPostId'を使います。それは他のどこかにあるはずです。 – spencdev