denodb icon indicating copy to clipboard operation
denodb copied to clipboard

Model not passed to "on" event callback

Open jdziek opened this issue 4 years ago • 1 comments

Hi, me again. I was indicated in the documentation, but it doesnt seem to work for me, that the model is passed on the "on" event listener Thats my code

import { DataTypes, Model } from "https://deno.land/x/denodb/mod.ts";
import db from "../databaseManager.ts";
import { format } from "https://deno.land/[email protected]/datetime/mod.ts";

const TOKEN_EXPIRY_LIMIT = 25;
class Flight extends Model {
  static table = "flights";
  data: any;
  // createdAt & updatedAt
  static timestamps = true;


  static fields = {

    key: {
      type: DataTypes.STRING,
      unique: true,
      allowNull: false,
    },
    value: {

      type: DataTypes.STRING,
      unique: true,
      allowNull: false,
    },

  };

}

await db.sync({ drop: true });
db.link([Flight]);

Flight.on("updating", (model: any) => {

})
  .on("creating", (model: any) => {
    console.log("onCreating");

    console.log(model);
  })
  .on("updated", (model: any) => {
    console.log("Updated:", model.id);
  })
  .on("created", (model: any) => {
    console.log("Updated:", model.id);
  });


export default Flight;

The 'model' in console.logs s undefined. As you can see i tried all of them and at this point im not sure if I missed something or not. Im using MongoDB.

jdziek avatar Jan 20 '21 14:01 jdziek

Same for me.

luxwarp avatar Feb 16 '21 14:02 luxwarp