'use strict';

module.exports = (sequelize, DataTypes) => {
  var Model = sequelize.define('<%= table %>', {<% _.each(fields, (field) => { %>
    <%= field.name %>: {
      type: DataTypes.<%= field.type %>,<% if (field.primaryKey) { %>
      primaryKey: true <% } %>
    },<% }) %>
  }, {
    tableName: '<%= table %>',
    <% if (underscored) { %>underscored: true,<% } %>
    <% if (!timestamps) { %>timestamps: false,<% } %>
    <% if (schema) { %>schema: process.env.DATABASE_SCHEMA,<% } %>
  });

  Model.associate = (models) => {<% _.each(references, (reference) => { %>
    Model.belongsTo(models.<%= reference.ref %>, {
      foreignKey: '<%= reference.foreignKey %>',
      <% if (reference.targetKey) { %>targetKey: '<%= reference.targetKey %>',<% } %>
      <% if (reference.as) { %>as: '<%= reference.as %>',<% } %>
    });
    <% }); %>
  };

  return Model;
};


'use strict';

module.exports = (sequelize, DataTypes) => {
  var Model = sequelize.define('<%= table %>', {<% _.each(fields, (field) => { %>
    '<%= field.name %>': {
      type: DataTypes.<%= field.type %>,<% if (field.primaryKey) { %>
      primaryKey: true <% } %>
    },<% }) %>
  }, {
    tableName: '<%= table %>',
    <% if (underscored) { %>underscored: true,<% } %>
    <% if (!timestamps) { %>timestamps: false,<% } %>
    <% if (schema) { %>schema: process.env.DATABASE_SCHEMA,<% } %>
  });

  Model.associate = (models) => {<% _.each(references, (reference) => { %>
    Model.belongsTo(models.<%= reference.ref %>, {
      foreignKey: '<%= reference.foreignKey %>',
      <% if (reference.targetKey) { %>targetKey: '<%= reference.targetKey %>',<% } %>
      <% if (reference.as) { %>as: '<%= reference.as %>',<% } %>
    });
    <% }); %>
  };

  return Model;
};


Support attribute names that start with a special character
Support attribute names that start with a special character
