Open Thomas-git opened 3 years ago
This is likely related to the custom idField. Can you set a break point in the clone mutation and get a better idea of what's going on?
Ok, After first line in .clone()
const { idField, tempIdField } = this.constructor
idField === 'id'
so it does not start good.
and on const id = ...
id is undefined.
Where should the idField
be extracted in the first place ?
The idField
gets placed on the Model class when passed in the options: https://github.com/feathersjs-ecosystem/feathers-vuex/blob/master/src/service-module/make-base-model.ts#L77.
You might need to verify that none of your service/model files has a duplicate service name or duplicate modelName
attribute set. What does your Language
class look like?
So, there is no duplicate service name nor modelName
If I add a static idField = 'language_code'
in Languages
model class, it works as expected. But if I understand the docs well, idField
should be set in the service options when using makeServicePlugin
. Again in the docs, I understand that modelName
is also an option of makeServicePlugin
. But if I do that, I have an error:
Error: The modelName property is required for Feathers-Vuex Models
Note that it feels more natural to me that idField be specified in the Model class and not in service definition. That's what is done when defining models server side using feathers-objection db adapter using idColumn
static property.
To answer your question, here is my Languages
class
class Languages extends BaseModel {
static modelName = 'languages'
/* static idField = 'language_code' */
// Define default properties here
static instanceDefaults () {
return {
}
}
static setupInstance (data, { store, models }) {
if (data.countries) {
// Turn countries into an array of Countries instances
data.countries = data.countries.map(data => new models.health.countries(data)) // eslint-disable-line new-cap
}
return data
}
}
export { Languages }
So am I faulty here, or there is something wrong in docs or in feathers-vuex code ?
Hmm... This appears to be a bug. Since we have a workaround I won't focus on fixing this for a little while. I'll leave this open to make sure we get to it. Thanks for reporting!
Steps to reproduce
I use FeathersVuexFind to query database. Everything is fine.
Problem arise in
removeLanguage(lang)
When I doconst clone = lang.clone()
clone
is emptyI also tried to get a fresh copy from the store with
const clone = Languages.getFromStore(lang.language_code).clone()
. But got the same empty clone.The Languages model
idField
is set tolanguage_code
in the service :Expected behavior
I expected the clone to be... a clone. With same properties. Goal here is to allow user to cancel his action. So I would like to keep a copy of the deleted object. Obviously, it fails because my clone is empty. That's not my first time using feathersVuex. But the first time I use a custom idField. Maybe it's related ?
Actual behavior
The clone as none of the properties of the cloned Languages model. At first I thought it was related to #226 but I'm not using a select as you can see. Source object
Cloned object
System configuration
Module versions (especially the part that's not working):
NodeJS version: Electron 9.3
Operating System: Archlinux
Browser Version: Electron 9.3
React Native Version: No. Using Quasar 1.14
Module Loader: Webpack 4.44