Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Update FIELDS different than Insert FIELDS #31

Closed
duard opened this issue May 10, 2018 · 1 comment
Closed

Update FIELDS different than Insert FIELDS #31

duard opened this issue May 10, 2018 · 1 comment

Comments

@duard
Copy link

duard commented May 10, 2018

Hi,
I'm using 'bookshelf-camelcase' plugin and that is my model class

import bookshelfR from '../../../../db_R';

const TABLE_NAME = 'tipo_medicamento';
class tipoMedicamento extends bookshelfR.Model {
  get idAttribute() {
    return 'codigoTipoMedicamento';
  }
  get tableName() {
    return TABLE_NAME;
  }
}
export default tipoMedicamento;

I can succes insert a new record using that function createResource and passing this as parameters:

Parameters

{
	"codigoTipoMedicamento": null,
	"descricao": "Problemas diversos", 
	"codigoBig": "atualizando registro 8"
}

Function

export function createResource(resource) {

  return new Resource({
    descricao: resource.descricao,
    codigoBig: resource.codigoBig
  })
    .save()
    .then(resource => {
      resource.refresh();
      return resource;
    });
}

But when I try to UPDATE my record, using this parameters and function I get some error about the primarykey field name is incorrect:

Parameters to updateRecord function

{
	"codigoTipoMedicamento": null,
	"descricao": "Problemas diversos", 
	"codigoBig": "atualizando registro 8"
}

Function updateRecord

export function updateResource(codigoTipoMedicamento, resource) {
  const data = {
    descricao: resource.descricao,
    codigoBig: resource.codigoBig
  };

  return new Resource({
    codigoTipoMedicamento
  })
    .save(data)
    .then(resource => resource.refresh());
}

table structure in mysql/mariadb

screenshot from 2018-05-10 04-38-40

The ERROR:


 error:  Error: ER_BAD_FIELD_ERROR: Unknown column 'codigoTipoMedicamento' in 'where clause'
    at Query.Sequence._packetToError (/home/duard/projetoSIG/sigpharmaAPI/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/home/duard/projetoSIG/sigpharmaAPI/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/home/duard/projetoSIG/sigpharmaAPI/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/duard/projetoSIG/sigpharmaAPI/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/duard/projetoSIG/sigpharmaAPI/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/duard/projetoSIG/sigpharmaAPI/node_modules/mysql/lib/Connection.js:103:28)
    at Socket.emit (events.js:160:13)
    at addChunk (_stream_readable.js:269:12)
    at readableAddChunk (_stream_readable.js:256:11)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onread (net.js:599:20)

@mesaugat
Copy link
Owner

codigoTipoMedicamento column name is still in camelCase. It might be some issue of bookshelf-camelcase.

You can remove bookshelf-camelcase and use snake_case instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants