WatermelonDB with ReactNative 0.64
I am trying to add a generate action inside the model like this:
class Events extends Model {
static table = 'events';
@field('event_at') event_at;
@field('trigger') trigger;
// other fields
@action async generateRandomData() {
console.log('ASYNC EVENT ACTION');
const randomData = [];
for (let i = 0; i < 10; i++) {
randomData.push(
// code to generate data
),
);
}
return await this.batch(randomData);
}
}
export default Events;
But how will be able to call the from inside a component function?
Things i have tried so far:
database.action(async () => {
await events.generateRandomData();
});
database.collections.get('events').generateRandomData()
and some other combinations... but in all places i was getting generateRandomData not defined.
I tried to find some help in the documentation and examples but couldn't find anything.