-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Comments
You will need to add a unique |
All my model definitions have a unique |
Mind posting one of them so I can see if anything else stands out? |
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
}
} |
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? |
Mitigated this by changing |
Are you using a custom adapter? |
No, I'm using sails-memory for testing purposes atm |
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);
}); |
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.
|
@andrewjmead Same problem, same solution. Thanks! |
@emersion Thanks for following up! |
The upper to lower case change worked for me as well. |
Yea, by the way, when you don't manually set |
@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. |
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 |
balderdashy/waterline#745: Identity must be in lower case. [ci skip]
Added PR (balderdashy/waterline-docs#51), can someone double check? |
@tjwebb, @devinivy can I get one of you to bless balderdashy/waterline-docs#51 so we can close this issue? Thanks! |
Thanks @devinivy! |
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. |
+1 to remove lowercase restriction! |
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 |
@japel @mlconnor are you guys talking about the same issue as OP (https://github.com/balderdashy/waterline/issues/745#issue-50383713) |
Any progress on this issue? |
@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. |
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:
Thanks so much for your help! |
Don't close this PLEASE! Don't mess with Lowercase, Uppercase, Camelcase, whatevercase! It should always be TheCaseIDecidedItToBe! |
@japel I agree with you! Do you mind making a PR to the ROADMAP.md file that suggests we remove this restriction? |
added to roadmap: do not mess with identity case (see #745)
I get this error when calling waterline.initialize()
The text was updated successfully, but these errors were encountered: