0
錯誤:
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();
}
}
是的,我知道這個事實。我明白了,這不是$ publicKey,而是$ primaryKey,謝謝! –