generator-angular-fullstack icon indicating copy to clipboard operation
generator-angular-fullstack copied to clipboard

Where can I define Sequelize associations?

Open ketysek opened this issue 10 years ago • 7 comments

Hello, I've just started with using this full-stack to create my new project. I've set up PostgreSQL as my main database, but here comes the problem: I am a little bit confused with model associations...where should I put them? Here is for example my product.model.js file ... is it possible to add a rule belongsTo(Something) here or not?

export default function(sequelize, DataTypes) {
  return sequelize.define('Product', {
    timestamps: true,
    _id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true
    },
    buyUrl: DataTypes.STRING,
    createdAt: 'dateAdded',
    updatedAt: false,
    ean: {
      type: DataTypes.STRING,
      unique: true,
      validate: {
        isNumeric: true,
      },
    }
}

ketysek avatar Jan 17 '16 21:01 ketysek

Ah, I found it :-D

ketysek avatar Jan 17 '16 21:01 ketysek

Hi @ketysek , How have you done ?

amoussard avatar Feb 18 '16 00:02 amoussard

@ketysek where did you put it?

ThiagoMiranda avatar Mar 01 '16 03:03 ThiagoMiranda

it can be put in file server\sqldb\index.js (I am using postgress)

ketysek avatar Mar 01 '16 07:03 ketysek

Thanks @ketysek . I've putted in there too. Just a quick question: where do you put a model that not necessarily have an api ( like a through table )?

ThiagoMiranda avatar Mar 01 '16 19:03 ThiagoMiranda

I think updating server\sqldb\index.js with a helpful comment to let those know where to define relationships. It would be easy and effective :)

andrewl913 avatar Jun 04 '16 03:06 andrewl913

help me, where did you put it?

AlexisNichel avatar Jun 09 '17 18:06 AlexisNichel