We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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"; }



34.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:

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