0

I'm trying to fetch a record from the database using Eloquent CRM. My table's primary key field name is "user_id". The weird thing is that everytime i use User::find() and pass a user_id number, i get

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' 
(SQL: select * from `users` where `id` = ? limit 1) (Bindings: array ( 0 => 8, ))

I'm assuming the ORM makes calls assuming the table's id field name is "id" instead of "user_id". How can i check that it correctly sees what it is supposed to see. I also tried to change the primary key field user_id to "id" as the ORM seem to expect and that worked but i'm following a naming convention in my database schema so i will like to stick to "user_id".

Any form of help will be appreciated.

Thanks

4

2 回答 2

1

我已经解决了这个问题。我所要做的就是正确阅读文档。不好意思急着问这么简单的问题。

Eloquent 假设任何表的主键字段默认命名为“id”。要更改它,只需将 $primaryKey 字段覆盖为数据库表中的相应字段名称。

于 2013-07-31T10:56:57.463 回答
-1
class User extends Eloquent implements ....

    public $publicKey = 'user_id';

    ...
于 2013-07-31T20:14:23.487 回答