雄辩的ORM不会在laravel中节省价值

时间:2015-02-11 19:20:18

标签: php laravel laravel-4 orm eloquent

我想使用Eloquent更新我的数据,但它给了我一些错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'od_logo.id' in 'where clause' (SQL: select * from `od_logo` where `od_logo`.`id` = 1 limit 1)

这是我的代码:

$logo = Logo::find($id);
$logo->logo_logoimg_name       = Input::get('logo_name');
$logo->logo_logoimg_path      = $logo_destinationPath . $logo_filename;
$logo->logo_faviconimg_name = $favicon_destinationPath . $favicon_filename;
$logo->save();

请在此代码中找到我错误的地方

1 个答案:

答案 0 :(得分:2)

因为您的主键列未被调用id(这是Laravel默认的假设),您必须在模型中指定它:

class Logo extends Eloquent {
    protected $primaryKey = 'logo_id';
}

来自docs

的引用
  

注意:Eloquent还会假设每个表都有一个名为id的主键列。您可以定义primaryKey属性来覆盖此约定。