Skip to content

Instantly share code, notes, and snippets.

@esarafianou
Created October 15, 2017 09:12
Show Gist options
  • Select an option

  • Save esarafianou/d53db9908b13872ff6bd87b5a6508aa5 to your computer and use it in GitHub Desktop.

Select an option

Save esarafianou/d53db9908b13872ff6bd87b5a6508aa5 to your computer and use it in GitHub Desktop.
import { Sequelize } from 'sequelize'
const sequelize = new Sequelize(
'postgres',
'postgres',
'postgres',
{
dialect: 'postgres',
host: 'localhost'
}
)
const User = sequelize.define('user', {})
const Project = sequelize.define('project', {})
const UserProjects = sequelize.define('userProjects', {
status: Sequelize.STRING
})
User.belongsToMany(Project, { through: UserProjects })
Project.belongsToMany(User, { through: UserProjects })
sequelize.sync({ force: true }).then(() => {
return User.create({
})
.then((user) => {
return Project.create({
})
.then((project) => {
return user.addProject(project, { through: { status: 'started' }})
})
})
})
export default sequelize
@esarafianou
Copy link
Author

docker commands:
docker rm -f harmoniseit
docker run --name harmoniseit -e POSTGRES_PASSWORD=postgres -p 127.0.0.1:5432:5432 -d postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment