Open ganeshkbhat opened 5 years ago
@ganeshkbhat Thanks for posting, we'll take a look as soon as possible.
For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.
schema
is false
or true
(primaryKey
is defined in extend configs and model attrs). autoPK
for sails-mongo
is not being picked up as a valid option, I am forced to specify an primaryKey
as _id
and the create a model with attributes _id
.unique
, autoIncrement
, min
,max
,minLength
,maxLength
and primaryKey
fields from within _id
model definition is throwing errors saying that these fields are not recognised/valid.Help requested, and any help is welcome to get autoPK:true
working with schema:true
. The goal here is to keep interchangeability with mysql/oracle:
const Waterline = require('waterline');
let waterline = new Waterline();
const datastores = {
"recAuth": {
"adapter": "mongodb",
"url": "mongodb://localhost:27017/recAuth"
}
};
const adapters = {
'mongodb': require('sails-mongo')
};
waterline.registerModel(Waterline.Collection.extend({
identity: 'def',
datastore: 'recAuth',
schema: false,
tableName: 'def',
autoPK: true,
primaryKey: '_id',
attributes: {
"_id": {
"type": "string"
},
"str": {
"type": "string",
"required": true
}
}
}));
function x(waterline) {
let pr = new Promise(function (resolve, reject) {
let model, modelFns;
waterline.initialize({
adapters: adapters,
datastores: datastores
}, (err, orm) => {
if (err) reject(err);
resolve(orm);
});
})
return pr;
}
async function getOrm(waterline) {
let orm = await x(waterline);
return orm;
}
async function testMongo() {
let sorm = await getOrm(waterline);
let res = await sorm.collections.def.create({str: 'test'}).fetch();
console.log(res);
let result = await sorm.collections.def.find({});
console.log(result);
}
testMongo();
I have raised a stackoverflow question to no help - https://stackoverflow.com/questions/53587393/sails-min-max-minlength-maxlength-for-number-and-string-types-gives-usererror Any help is welcome.
@ganeshkbhat looks like you're using Waterline standalone, but if you have a chance would you try reproducing this in a new Sails app and link to the repo? (Might help us better understand what's going on)
Hey @ganeshkbhat , we're moving all the Waterline issues to the main Sails repo (balderdashy/sails) for closer monitoring and greater exposure to the community. I see the last update on this one was reproducing the issue in a repo. We appreciate you taking the time to provide all you have so far, feel free to let us know how this one is going. Thanks.
Waterline version: "waterline": "^0.13.5", Node version: 10.7.0 NPM version: 6.1.0 Operating system: Ubuntu 18.x
I have read through the issue and have tried adding autoPK: true but seems like I am unable to use it. https://github.com/balderdashy/waterline/issues/301 It fails asking for Primary key to be defined.
Error when no Primary key is defined.
{ userError: Could not find a primary key attribute on the model
Action. All models must contain an attribute that acts as the primary key and is guaranteed to be unique.
Error when Primary Key is defined.
userError: The model 'Action' defined a primary key of 'id' that has an invalid type. Valid primary key types are 'number' and 'string'
Both way this fails. I am using sails-mongo as the adapter.