WatermelonDB
WatermelonDB copied to clipboard
Error: Possible Unhandled Promise Rejection ... undefined is not an object (evaluating 'this.collection.database')
I just got started with watermelondb on a new installation of react native.
But i get this error when i use @writer
decorator or use this.
in the model class
Here is the code https://github.com/josephsintum/AwesomeTSProject
when i have this
class CategoryModel extends Model
....
run() {
console.log(this);
}
@writer async clear() {
await this.collections
.get<CategoryType & Model>('categories')
.query()
.markAllAsDeleted()
.catch(err => console.error({createErr: err}));
}
}
...
or just use this.collections, I get this error
Possible Unhandled Promise Rejection (id: 0):
TypeError: undefined is not an object (evaluating 'this.collection.database')
get@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.AwesomeTSProject:128006:31
Also when i run the run()
method with console logs this
i get {"__changes": null, "_isEditing": false, "_preparedState": null, "_raw": undefined, "_subscribers": [], "collection": undefined}
this shows that the this operator is undefined or maybe I'm not invoking the clear() or run() methods correctly
how can I fix this thank you
Extra Info
"@nozbe/watermelondb": "^0.23.0",
"react": "17.0.2",
"react-native": "0.65.1",
Try clearing data of the app, The schema dosen't seem to update without it in my case.
- Clear data of your app
- Check if you declared all models in your adapter
- Check if you have all tables in schema
Thank you That worked