WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

Error: Possible Unhandled Promise Rejection ... undefined is not an object (evaluating 'this.collection.database')

Open josephsintum opened this issue 3 years ago • 1 comments

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",

josephsintum avatar Aug 29 '21 08:08 josephsintum

Try clearing data of the app, The schema dosen't seem to update without it in my case.

pulbyte avatar Dec 06 '21 09:12 pulbyte

  1. Clear data of your app
  2. Check if you declared all models in your adapter
  3. Check if you have all tables in schema

alicja-mruk avatar Sep 02 '22 10:09 alicja-mruk

Thank you That worked

josephsintum avatar Sep 02 '22 16:09 josephsintum