Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

findFirst对主键的支持(findFirst supported primary key)???

表的结构(Table):

CREATE TABLE sessions ( sessionid character varying(32) NOT NULL, userid integer NOT NULL DEFAULT 0, userip character varying(20), browser character varying(200), lastpage character varying(100), lasttime integer NOT NULL DEFAULT 0, CONSTRAINT sessionspkey PRIMARY KEY (session_id) )

执行查询:

$sessionid = md5(sessionid()); \App\Models\Sessions::findFirst($session_id );

发生错误(Error): Column 'cc0965e7334b1172f5ab477d40c405f8' doesn't belong to any of the selected models (1)

Hi, try this on your model:

 public function getSequenceName()
    {
        return "name_of_you_primary_key";
    }

No effect

Hi, try this on your model:

public function getSequenceName()
 {
     return "name_of_you_primary_key";
 }


33.6k
Accepted
answer

You are passing a condition there, you have to use:

$session_id = md5(session_id()); 
\App\Models\Sessions::findFirstBySessionId($session_id );

只能这样了

You are passing a condition there, you have to use:

```php $sessionid = md5(sessionid()); \App\Models\Sessions::findFirstBySessionId($session_id ); ```