如何在Laravel 4中更新没有id的Eloquent数据 [英] How can I update data with Eloquent without id in Laravel 4

查看:150
本文介绍了如何在Laravel 4中更新没有id的Eloquent数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想更新 FaqTrans 数据库时,但是这个datase有两个主键(faq_ida和lang) $ table-> primary array('lang','faq_id')); 。所以我不需要一个 id 列与auto_increment。

When I want to update the FaqTrans database, but this datase have two primary key (faq_ida and lang) $table->primary(array('lang', 'faq_id'));. so I don't need a id column with auto_increment.

但是,当我使用以下代码更新数据库,错误消息提示我没有 id 列。

However, when I use the following code to update the database, the error message hint me there is no id column.

$faq_trans = FaqTrans::where('faq_id','=',$faq_id)->where('lang','=',$lang)->first();
$faq_trans->lang  = Input::get('lang');
$faq_trans->body  = Input::get('body');
$faq_trans->title = Input::get('title');
$faq_trans->save();

错误信息


SQLSTATE [42S22]:未找到列:1054未知列'id'在'其中
子句'(SQL:update FAQtrans set body =?, updated_at =?where
id is null )(Bindings:array(0 =>'adfadaaadfadaa',1 =>
'2013-07-04 11:12:42',))

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update FAQtrans set body = ?, updated_at = ? where id is null) (Bindings: array ( 0 => 'adfadaaadfadaa', 1 => '2013-07-04 11:12:42', ))

,当我添加 id 列时,代码工作正常...

and when I added an id column, the code works fine...

有没有办法可以更新没有ID列的数据库?

are there any way can I update the database without ID column ?

推荐答案

Laravel / Eloquent不支持复合主键。

Laravel / Eloquent doesn't support composite primary keys.

当您检查Eloquent Model类时,您可以看到主键只能是一个字符串,用于创建WHERE子句。

When you check the Eloquent Model class, you can see that the primary key can only be a string, which is used to create the WHERE clause.

这篇关于如何在Laravel 4中更新没有id的Eloquent数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆