stribny / auth-quickstart

Authentication Quickstart with Express, Passport and Sequelize
MIT License
47 stars 21 forks source link

Why Model is required? #1

Closed davidyapdy closed 7 years ago

davidyapdy commented 7 years ago

In the file "./app/controllers/signupController.js", you included Model to be required from "../model/models.js"

var bcrypt = require('bcryptjs'),
    Model = require('../model/models.js')

Why is model.js is required? Are we referring to this?

var User = connection.define('users', UserMeta.attributes, UserMeta.options)

I'm learning how to use this and I hope you don't mind me asking.

stribny commented 7 years ago

Hi David!

I am sorry that I didn't notice your post earlier.

In the signupController.js you can see that I use the Model to create a new user: Model.User.create(newUser).then(....

Basically, it gives us access to all models we defined for Sequelize in the models.js file. User is one of the defined models and we can define more models and relationships between them. Have a look here how to do that: http://docs.sequelizejs.com/en/latest/docs/models-definition/.

Hope this helps!