laravelにて現状以下のSQLが生成されています
sql
1select * from `users` inner join `user_microposts` on `users`.`id` = `user_microposts`.`microposts_id` where `user_microposts`.`user_id` = ? and `microposts_id` = ?
しかし、本来は以下のようなSQLを生成してほしいです
sql
1select * from `users` inner join `user_microposts` on `users`.`id` = `user_microposts`.`user_id` where `user_microposts`.`user_id` = ? and `microposts_id` = ?
laravelのソースは以下の通りです。
php
1//User.php(model) 2public function is_favoritting($userId) { 3 return $this->favorittings()->where('microposts_id', $userId)->exists(); 4 } 5 6public function favorittings(){ 7 return $this->belongsToMany(User::class, 'user_microposts', 'user_id', 'microposts_id')->withTimestamps(); 8 }
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/20 09:22