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.

Model.fetchAll not working

See original GitHub issue

When I am trying to all all object via Bookshelf then it is returning incorrect result.

var uuid = require('node-uuid');
var Bookshelf = require('bookshelf');
var Knex = require('knex');
var bookshelf = Bookshelf(Knex({}));
var schema = bookshelf.knex.schema;

schema.createTable('binary_uuid_test', function(table) {
  table.binary('uuid');
  table.string('name');
})

it('loads objects properly', function() {
  // These are uuid.v1()
  var uuids = ['d96d40d1-fcc9-11e5-9b8d-87b1687276b9', 'd96d40d2-fcc9-11e5-9b8d-87b1687276b9'];
  var s_uuids = ['d96d40d1-fcc9-11e5-9b8d-87b1687276b9', 'd96d40d2-fcc9-11e5-9b8d-87b1687276b9'];

  var SubSite = bookshelf.Model.extend({
    idAttribute: 'uuid',
    tableName: 'binary_uuid_test',

    initialize: function() {
      this.on('saving', this._generateId);
    },

    _generateId: function (model, attrs, options) {
      if (model.isNew()) {
        model.set(model.idAttribute, buildBuffer(uuids.pop()));
      }
    }
  });

  function buildBuffer(string) {
    return (new Buffer(uuid.parse(string)));
  }

  var subsite = new SubSite({ name: 'Kuldeep Aggarwal' }),
      subsite1 = new SubSite({ name: 'Kd Aggarwal' });

  return Promise.all([subsite1.save(), subsite.save()])
    .then(function() {
      return SubSite.fetchAll()
        .then(function(collection) {
          expect(_.map(collection.models, function(model) {
            return uuid.unparse(model.id);
          })).to.eq(s_uuids);
        });
    });
});

This test is getting failed.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
rhys-vdwcommented, Apr 8, 2016

format is called after object is initialized from DB -> Model Object and parse is called when object is saved to DB. right?

Other way around.

parse: columns -> attributes format: attributes -> columns

0reactions
crunchtime-alicommented, Jul 19, 2017

The project leadership of Bookshelf recently changed. In an effort to advance the project we close all issues older than one year.

If you think this issue needs to be re-evaluated please post a comment on why this is still important and we will re-open it.

We also started an open discussion about the future of Bookshelf.js here https://github.com/bookshelf/bookshelf/issues/1600. Feel free to drop by and give us your opinion. Let’s make Bookshelf great again

Read more comments on GitHub >

github_iconTop Results From Across the Web

IG cookbook model.fetchAll(function() {}); NOT working
fetchAll (function() {}); NOT working. I'm using apex 20.2 and universal theme. I copied the code in the IG Cookbook dynamic total below....
Read more >
cursor.fetchall() or other method fetchone() is not working
After trying it multiple times. I understand that you always have to commit ( db.commit() ) your transaction into databases before executing ...
Read more >
PDOStatement::fetchAll - Manual - PHP
If you are trying to call PDOStatement::fetchAll and is not getting the result set as expected (empty instead), check if you called PDOStatement::execute...
Read more >
sqlite3 — DB-API 2.0 interface for SQLite databases — Python ...
First, we need to create a new database and open a database connection to allow sqlite3 to work with it. Call sqlite3.connect() to...
Read more >
X DevAPI User Guide :: 9.4 Fetching All Data Items at Once
... of using fetchOne() explained at Section 9.3, “Working with Data Sets”, ... X DevAPI also provides a pattern using fetchAll() , which...
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