TypeError: sanitizer is not a function
While I try to insert json data, I get:
TypeError: sanitizer is not a function
The column type is string in schema, and the decorators are setup like in docs: https://github.com/Nozbe/WatermelonDB/blob/master/docs/Advanced/AdvancedFields.md#json
@ndrkltsk Can you show definitions of the field and the sanitize function?
Hello, I have the same error Model
import {field, json} from '@nozbe/watermelondb/decorators'
export default class Novel extends Model {
static table = tableName;
//some fields
@json('genres', genresSanitizer) genres;
}
const genresSanitizer = input => {
return input;
}
Schema
import {tableSchema} from '@nozbe/watermelondb'
export default tableSchema({
name,
columns: [
//...
{name: 'genres', type: 'string', isOptional: true},
]
})
my input on genres field is an array:
["Tiên Hiệp"]
my error:
TypeError: sanitizer is not a function
at Novel.set [as genres] ...
package.json
"@nozbe/watermelondb": "^0.10.1",
"react": "16.6.3",
"react-native": "^0.58.4",
"es6-symbol": "^3.1.1",
What's your babel config?
@radex .babelrc
{
"presets": [
"module:metro-react-native-babel-preset"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
package.json
"@babel/plugin-proposal-decorators": "^7.3.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "24.1.0",
"babel-preset-react-native": "^5",
"@babel/runtime": "^7.2.0",
"babel-plugin-idx": "^2.2.0",
"babel-plugin-transform-remove-console": "^6.9.0",
@vdthieu Were you able to resolve this?
It was a hoisting issue on my side, moving the sanitizer const above the export default worked for me
The problem was happening with JSON fields on model. I switched them to TEXT and the sanitizer error gone. "@json("geo_json") geo_json;" TO "@text("geo_json") geo_json;"