question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update FIELDS different than Insert FIELDS

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ricardogracacommented, May 10, 2018

No, Portugal and it’s ricardograça 😉

Can you try with the latest version (0.13.3) and see if the problem persists? I think what you’re reporting was already fixed. Also, there’s a built-in case-converter plugin now:

bookshelf.plugin('case-converter')
0reactions
duardcommented, May 10, 2018

@ricardogama using latest versions of knex and bookshelf and ‘bookshelf-camelcase’ the code works ! using latest versions of knex and bookshelf and ‘case-converter’ the code works !

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update fields - Microsoft Support
Update all fields in a document · Press Ctrl + A. · Press F9. · If your document has tables with fields or...
Read more >
Insert and update fields - Adobe Support
Open the topic or the master page that contains the field. · Double-click on the field that you want to edit. · In...
Read more >
Working with Fields and Forms in Word 2016 - InformIT
To update a single field, select it (or click anywhere in it) and press F9, or right-click the field and choose Update Field....
Read more >
How to Update Fields in Microsoft Word (One or All Fields)
Right-click the field and select Update Field. Depending on the type of field, another dialog box may appear where you can select other...
Read more >
Updating Fields in Word – How it Works - DocTools
In order for fields to show the correct result, they must be updated. Some types of fields are updated automatically by Word whereas...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found