Skip to content

Add options to add virtual fields to table and custom associations #679

@chiendv

Description

@chiendv

Hi team.

I had made and updated in my forked repository to add new options to support to:

  • Add virtual fields for any generated models
  • Add custom associations to any generated models ( It useful because sometimes we not allowed to update the database directly)
  • Allow to overwrite models "additional" for specified tables

new options look like this:

const auto = new SequelizeAuto('database', 'user', 'pass', {
   ///...
    additional: {
        timestamps: false,
        paranoid: true
        // ...options added to each model
    },
    additionalTables: {
      customer {
        options: {
          timestamps: false,
          paranoid: false
        },
        virtualFields: {
          "full_name": {
            get: "return `${this.first_name} ${this.last_name}`" //value is plain text add to model get/set function
          }
        }
      }
    },
    additionalRelations:[
      `Customer.belongsToMany(Product, { as: 'customerProducts', through: OrderItem, foreignKey: "order_id", otherKey: "product_id" });`
    ],
    //...
})

You can test here https://www.npmjs.com/package/@chiendv/sequelize-auto/v/0.9.0-beta.1

You it is good to merge to this main repository and will create a PR.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions