Skip to content

Commit

Permalink
Merge pull request #13 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[fix] fixes #12
  • Loading branch information
scott-wyatt authored Aug 5, 2018
2 parents a4ec7c2 + 51d1778 commit 0902f56
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/SequelizeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export class SequelizeResolver extends FabrixResolver {
/**
*
*/
build(options = { }) {
build(dataValues, options = { }) {
if (this._sequelizeModel) {
return this._sequelizeModel.build(options)
return this._sequelizeModel.build(dataValues, options)
}
}

Expand Down Expand Up @@ -173,6 +173,10 @@ export class SequelizeResolver extends FabrixResolver {
return this._sequelizeModel.decrement(fields, options)
}
}

/**
*
*/
describe(schema, options = { }) {
if (this._sequelizeModel) {
return this._sequelizeModel.describe(schema, options)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-sequelize",
"version": "1.1.8",
"version": "1.1.9",
"description": "Spool - Datastore Spool for Sequelize.js http://sequelizejs.com",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down
58 changes: 58 additions & 0 deletions test/integrations/spool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,64 @@ describe('Spool', () => {
})
})

it('should build and save an instance with associations', (done) => {
const instance = global.app.models.User.build({
name: 'test',
roles: [
{
name: 'test'
}
]
}, {
include: [
{
model: global.app.models.Role.instance,
as: 'roles'
}
]
})
instance.save().then(i => {
assert.ok(i.roles)
assert.equal(i.roles.length, 1)
done()
})
.catch(err => {
done(err)
})
})


it('should build, save, reload an instance with associations', (done) => {
const instance = global.app.models.User.build({
name: 'test',
roles: [
{
name: 'test'
}
]
}, {
include: [
{
model: global.app.models.Role.instance,
as: 'roles'
}
]
})
instance.save().then(i => {
assert.ok(i.roles)
assert.equal(i.roles.length, 1)
return i.reload()
})
.then(i => {
assert.ok(i.roles)
assert.equal(i.roles.length, 1)
done()
})
.catch(err => {
done(err)
})
})

it('should create an instance', (done) => {
const instance = global.app.models.testModel.create({name: 'test'})
.then(i => {
Expand Down

0 comments on commit 0902f56

Please sign in to comment.