-
Notifications
You must be signed in to change notification settings - Fork 19
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
Breaks on 3.1 to 4.0 but nothing in readme to indicate what they are #93
Comments
yea changed that to |
looks like
doesn't work. // Sends back corresponding attached schemas when get when id 'schema' is used with get from client
module.exports = function () {
return function(hook) {
if (hook.id === 'schemas') {
console.log('in get schemas', hook.service)
// setting hook result will send schemas to client
hook.result = hook.service.Model.schemas
// console.log('getting schema', hook.result)
}
return hook
}
} works now with // Sends back corresponding attached schemas when get when id 'schema' is used with get from client
module.exports = function () {
return function(hook) {
if (hook.id === 'schemas') {
console.log('in get schemas', hook.service.options.Model.schemas)
// setting hook result will send schemas to client
hook.result = hook.service.options.Model.schemas
// console.log('getting schema', hook.result)
}
return hook
}
} So I found it myself so you can close this issue but... can you please make a few comments in the readme for the benefit of others about this change to the object structure (and why?). |
That's a good point actually, even the automatically generated Changelog didn't turn out to be very illuminating. You can find the migration information in crow.docs.feathersjs.com/migrating.html#database-adapters. However, it shouldn't break anything in the initialization so more information about your setup and the error message would be helpful. |
The issue is illustrated above. First to the model object I attach a schema object that holds a schema for records in that model. It was the easiest most obvious place to attach that for later use (schema goes with collection it is used against). const NeDB = require('nedb')
// const path = require('path')
module.exports = function (app, service) {
// TODO find application root and save to app object for user here instead of __dirname
// with this file in /helpers directory
// console.log(__dirname + '/../' + app.get('nedb').schemaPath + '/' + service + '.schemas.js')
const schemas = require(__dirname + '/../' + app.get('nedb').schemaPath + '/' + service + '.schemas.js')
const dbPath = app.get('nedb').path
const Model = new NeDB({
filename: `${dbPath}/${service}.db`,
autoload: true
})
Model.schemas = schemas
if(app.get('nedb').autoCompact) {
Model.persistence.setAutocompactionInterval(app.get('nedb').autoCompactInterval)
}
// console.log(Model.schemas.name)
return Model
} Later the client can issue a get with a custom id "schema" and the corresponding hook on the server (the code above) will return the schema rather than any record from the collection/service. The client uses that schema to make custom forms from vai framework (vuejs/quasar) that the service records then populate. Also I have an init hook that needs access to the schema for record initialzation with default values from the schema. const getschemas = require('../../hooks/getschemas.js')
//const init = require('../../hooks/init.js');
// const pDebounce = require('p-debounce')
const init = function () {
// The hook function itself is returned.
return function(hook) {
// const { method, type, data, service } = hook;
const { data, service } = hook
// console.log('nedb model from hook in circuits.hooks.js', service.options.Model)
const schema = service.options.Model.schemas
// console.log('hook log\n', data, schema)
// validate name unique
for (let field in schema) {
// console.log('field, schema', field, schema[field])
if (!data[field]) {
data[field] = schema[field].default // try to initize on type instead of default
// console.log(field, data[field])
}
}
data.on = false // maintain circuit state
//console.log('doc to be written', hook.data);
return hook
}
} Basically anywhere where I needed access to the schema attached to the model the extra .options key was introduced that broke it. What was the point of adding that key anyway? Was that to support the hookless call?? As is usually the case accessing a comlicated object directly is problematic. So the service object should include a getter/setter for the You should probably add getter/setter for any part of the service object that end users might have reasonable reason to access/amend |
|
I amended Model only where it was created not via the service so no issue there. It was later when accessing it inside a hook the issue comes. I'm not sure I agree with your comment that So this then is maybe the issue. |
I can't reproduce |
I tried updating from 3.1 to 4 and no surprise it broke my application. When I roll back all is fine.
The readme does not mention anything about what the breaking changes are which makes it time consuming to track them down. Just even a few comments in the readme would have been helpful.
Can you please indicate where it is likely I've have to make changes. Looks like the options have changed? Looks like you pass the model as a key value instead of the model itself? Anything else?
The text was updated successfully, but these errors were encountered: