エラー:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `genre_books` set `provider_id` = ?, `genre_id` = ? where `id` is null) (Bindings: array ( 0 => 3, 1 => 466284, ))
一部のデータは正常に追加されていますが、そのテーブルには追加されていますが、更新の途中でこのエラーが発生します。
モデル:
class GenreBook extends Eloquent {
public $table = 'genre_books';
public $timestamps = false;
public $publicKey = 'book_id';
public function setRank($a) {
$this->sort_order = $a;
}
public function setProviderId($a) {
$this->provider_id = $a;
}
public function setBookId($a) {
$this->book_id = $a;
}
public function setGenreId($a) {
$this->genre_id = $a;
}
}
コントローラーのコード:
GenreBook::unguard();
foreach($bookList as $genreId => $books) {
if(count($books) > 0) {
foreach ($books as $book) {
$genreBookRecord = GenreBook::where('book_id',$book['asin'])->where('provider_id',3)->first();
$newGenreBook->setProviderId(3);
$newGenreBook->setBookId($book['asin']);
$newGenreBook->setRank($book['rank']);
$newGenreBook->setGenreId($genreId);
$newGenreBook->save();
}
}