Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on init: TypeError: Cannot read property 'identity' of undefined #5852

Closed
marcelklehr opened this issue Nov 28, 2014 · 28 comments
Closed

Comments

@marcelklehr
Copy link

I get this error when calling waterline.initialize()

node_modules/waterline/lib/waterline/adapter/sync/strategies/alter.js:42
 = _.find(self.query.waterline.schema, {tableName: self.collection}).identity;

TypeError: Cannot read property 'identity' of undefined
    at afterDescribe (node_modules/waterline/lib/waterline/adapter/sync/strategies/alter.js:42:91)
    at bound (node_modules/waterline/node_modules/lodash/dist/lodash.js:957:21)
    at applyInOriginalCtx (node_modules/waterline/lib/waterline/utils/normalize.js:416:80)
    at wrappedCallback (node_modules/waterline/lib/waterline/utils/normalize.js:315:18)
    at _normalizeCallback.callback.success (node_modules/waterline/node_modules/node-switchback/lib/normalize.js:33:31)
    at _switch (node_modules/waterline/node_modules/node-switchback/lib/factory.js:35:28)
    at node_modules/sails-memory/lib/database.js:163:5
    at null._onTimeout (node_modules/sails-memory/lib/database.js:122:5)
    at Timer.listOnTimeout (timers.js:133:15)
@particlebanana
Copy link
Contributor

You will need to add a unique identity field to your model definitions. This needs a much better error message.

@marcelklehr
Copy link
Author

All my model definitions have a unique identity field.

@particlebanana
Copy link
Contributor

Mind posting one of them so I can see if anything else stands out?

@marcelklehr
Copy link
Author

Sure:

/**
 * Document
 */
module.exports = {
  identity: 'document'
, connection: 'default'

, attributes: {
    type: 'string'

  , pendingChanges: {
      collection: 'pendingChange'
    , via: 'document'
    }

    // hasMany snapshots
  , snapshots: {
      collection: 'snapshot'
    , via: 'document' // Snapshot.document
    }

    // hasMany authors
  , authors: {
      collection: 'user'
    , via: 'documents'
    , dominant: true
    }

    //Automagically created:
//, id (auto-incrementing)
//, createdAt
//, updatedAt

  }
}

@marcelklehr
Copy link
Author

I just noticed this: https://github.com/balderdashy/waterline/blob/master/example/raw/bootstrap.js#L37

Does that mean, that I should add an identity to my adapter as well?

@marcelklehr
Copy link
Author

Mitigated this by changing defaults:migrate to drop as a short-term solution.

@particlebanana
Copy link
Contributor

Are you using a custom adapter?

@marcelklehr
Copy link
Author

No, I'm using sails-memory for testing purposes atm

@particlebanana
Copy link
Contributor

Given this with sails-memory I don't have any problems.

var Waterline = require('waterline');

// Instantiate a new instance of the ORM
var orm = new Waterline();


//////////////////////////////////////////////////////////////////
// WATERLINE CONFIG
//////////////////////////////////////////////////////////////////

// Require any waterline compatible adapters here
var memoryAdapter = require('sails-memory');


// Build A Config Object
var config = {

  // Setup Adapters
  // Creates named adapters that have have been required
  adapters: {
    memory: memoryAdapter
  },

  // Build Connections Config
  // Setup connections using the named adapter configs
  connections: {
    'default': {
      adapter: 'memory'
    }
  },

  defaults: {
    migrate: 'alter'
  }

};


//////////////////////////////////////////////////////////////////
// WATERLINE MODELS
//////////////////////////////////////////////////////////////////

var Document = Waterline.Collection.extend({

  identity: 'document',
  connection: 'default',

  attributes: {
    name: {
      type: 'string'
    }
  }

});


// Load the Models into the ORM
orm.loadCollection(Document);


//////////////////////////////////////////////////////////////////
// START WATERLINE
//////////////////////////////////////////////////////////////////

// Start Waterline passing adapters in
orm.initialize(config, function(err, models) {
  if(err) throw err;
  console.log('LOADED', models);
});

@andrewjmead
Copy link

I'm getting that same error. I was able to debug it to be an issue with capitalization in the identity name. It would run once fine, then it would error out the second time. I updated the name to lower case and blasted the DB away and everything was fine.

// Name that did not work
identity: "linkStatus",

// Name that did work
identity: "linkstatus",

@emersion
Copy link

emersion commented Feb 7, 2015

@andrewjmead Same problem, same solution. Thanks!

@andrewjmead
Copy link

@emersion Thanks for following up!

@jeremiahrhall
Copy link

The upper to lower case change worked for me as well.

@tjwebb
Copy link
Contributor

tjwebb commented Mar 20, 2015

Yea, by the way, when you don't manually set identity, sails automatically sets it to be lowercase.

@devinivy
Copy link

@tjwebb I thought identities were always lowercase–how do you "manually" set an identity with case? If identities are always lowercase and that's not in the docs, let's add it. Also, if identities should be lowercase, we should add a useful error message.

@tjwebb
Copy link
Contributor

tjwebb commented Mar 20, 2015

I don't see it documented anywhere but other github comments. Here's some relevant code: https://github.com/balderdashy/waterline/blob/master/lib/waterline.js#L116

We should add clarity on this behavior in https://github.com/balderdashy/waterline-docs/blob/master/models.md

dmarcelino referenced this issue in balderdashy/waterline-docs Mar 20, 2015
balderdashy/waterline#745: Identity must be in lower case.
[ci skip]
@dmarcelino
Copy link
Member

Added PR (balderdashy/waterline-docs#51), can someone double check?

@dmarcelino
Copy link
Member

@tjwebb, @devinivy can I get one of you to bless balderdashy/waterline-docs#51 so we can close this issue? Thanks!

@dmarcelino
Copy link
Member

Thanks @devinivy!

@devinivy
Copy link

Blessed! But I am interested in removing the lowercase restriction some day. When you read that in the docs, it sounds really bizarre. In any case, adding this to the docs was the best short-term solution.

@japel
Copy link

japel commented May 28, 2015

+1 to remove lowercase restriction!
If I define a model mYoWeSoMeMoDeL.js I would like to call it the same way in waterline

@mlconnor
Copy link

the lower case constraint even seeps into the code. now we have to use models.access_token instead of camel case accessToken.

+1 to remove restriction

@tjwebb tjwebb reopened this Nov 11, 2015
@tjwebb
Copy link
Contributor

tjwebb commented Nov 11, 2015

@japel @mlconnor are you guys talking about the same issue as OP (https://github.com/balderdashy/waterline/issues/745#issue-50383713)

@GeorgeSapkin
Copy link

Any progress on this issue?

@gaurav21r
Copy link

@andrewjmead Its been many months but your solution is still very very helpful! @tjwebb @particlebanana In addition to the addition in the docs repo, I think we should have a better error message as well. TypeError: Cannot read property 'identity' of undefined is pretty obscure 😝

@sailsbot
Copy link

sailsbot commented Jan 8, 2016

Thanks for posting, @marcelklehr. I'm a repo bot-- nice to meet you!

It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

  • review our contribution guide to make sure this submission meets our criteria (only verified bugs with documented features, please; no questions, commentary, or bug reports about undocumented features or unofficial plugins)
  • create a new issue with the latest information, including updated version details with error messages, failing tests, and a link back to the original issue. This allows GitHub to automatically create a back-reference for future visitors arriving from search engines.

Thanks so much for your help!

@sailsbot sailsbot closed this as completed Jan 8, 2016
@japel
Copy link

japel commented Jan 9, 2016

Don't close this PLEASE! Don't mess with Lowercase, Uppercase, Camelcase, whatevercase! It should always be TheCaseIDecidedItToBe!

@devinivy
Copy link

devinivy commented Jan 9, 2016

@japel I agree with you! Do you mind making a PR to the ROADMAP.md file that suggests we remove this restriction?

particlebanana referenced this issue in balderdashy/waterline Jan 18, 2016
added to roadmap: do not mess with identity case (see #745)
@johnabrams7 johnabrams7 transferred this issue from balderdashy/waterline May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests