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 ( session_id character varying(32) NOT NULL, user_id integer NOT NULL DEFAULT 0, user_ip character varying(20), browser character varying(200), last_page character varying(100), last_time integer NOT NULL DEFAULT 0, CONSTRAINT sessions_pkey PRIMARY KEY (session_id) )

执行查询:

$session_id = md5(session_id()); \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.7k
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:

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