Modifying the default primary key in Thinkjs

Source: Internet
Author: User

Error message:

{Error:ER_BAD_FIELD_ERROR:Unknown column ' a_role.id ' in ' FIELD list '

To restore a scene:

A_role This table has no self-increment ID, and the primary key is Roleid. This error occurs if you write query data SQL for this table in the controller of THINKJS.

Workaround:

The Modified code:

1 Async listaction () {2Let GetData = This. get ();3         Let role = This.model (' a_role ');4        role._pk = ' Roleid ';5Let whereobj = {};//Status: 1: normal;-1: Disabled6         if(Getdata.roleid) {//role ID7whereobj[' Roleid '] =Getdata.roleid;8         }9         if(Getdata.rolename) {//Role NameTenwhereobj[' rolename ' = [' like ', '% ' + getdata.rolename + '% ']; One         } A         if(getdata.state && Getdata.state! =-99) { -Whereobj.state =getdata.state; -         } theLet result = awaitrole. Field (' Roleid,rolename,state ') - . where (whereobj) -. Order ("Roleid ASC") - . Page (Getdata.pagenumber, getdata.pagesize) + . Countselect (); -         return  This. JSON ({total:result.count, rows:result.data}); +}

Modifying the default primary key in Thinkjs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.