不要怂,就是干,撸起袖子干!

Commit 63677587 by Mick Hansen

more stuff

1 parent 74c6204a
......@@ -1186,7 +1186,9 @@ module.exports = (function() {
var addDefaultAttributes = function() {
var self = this
, defaultAttributes = {
, head = {}
, tail = {}
, head = {
id: {
type: DataTypes.INTEGER,
allowNull: false,
......@@ -1196,18 +1198,29 @@ module.exports = (function() {
}
if (this.hasPrimaryKeys) {
defaultAttributes = {}
head = {}
}
if (this.options.timestamps) {
defaultAttributes[Utils._.underscoredIf(this.options.createdAt, this.options.underscored)] = {type: DataTypes.DATE, allowNull: false}
defaultAttributes[Utils._.underscoredIf(this.options.updatedAt, this.options.underscored)] = {type: DataTypes.DATE, allowNull: false}
tail[Utils._.underscoredIf(this.options.createdAt, this.options.underscored)] = {type: DataTypes.DATE, allowNull: false}
tail[Utils._.underscoredIf(this.options.updatedAt, this.options.underscored)] = {type: DataTypes.DATE, allowNull: false}
if (this.options.paranoid)
defaultAttributes[Utils._.underscoredIf(this.options.deletedAt, this.options.underscored)] = {type: DataTypes.DATE}
tail[Utils._.underscoredIf(this.options.deletedAt, this.options.underscored)] = {type: DataTypes.DATE}
}
Utils._.each(defaultAttributes, function(value, attr) {
var existingAttributes = Utils._.clone(self.rawAttributes)
self.rawAttributes = {}
Utils._.each(head, function(value, attr) {
self.rawAttributes[attr] = value
})
Utils._.each(existingAttributes, function(value, attr) {
self.rawAttributes[attr] = value
})
Utils._.each(tail, function(value, attr) {
if (Utils._.isUndefined(self.rawAttributes[attr])) {
self.rawAttributes[attr] = value
}
......
......@@ -42,7 +42,7 @@ module.exports = (function() {
Object.defineProperty(DAO.prototype, 'values', {
get: function() {
return this.dataValues
return this.get()
}
})
......@@ -88,11 +88,15 @@ module.exports = (function() {
}
DAO.prototype.get = function (key) {
if (key) {
if (this._customGetters[key]) {
return this._customGetters[key].call(this)
return this._customGetters[key].call(this, key)
}
return this.dataValues[key]
}
return this.dataValues
}
DAO.prototype.set = function (key, value, options) {
var values
, originalValue
......@@ -126,7 +130,7 @@ module.exports = (function() {
// If not raw, and there's a customer setter
if (!options.raw && this._customSetters[key]) {
this._customSetters[key].call(this, value)
this._customSetters[key].call(this, value, key)
} else {
// Check if we have included models, and if this key matches the include model names/aliases
if (this.options && this.options.include && this.options.includeNames.indexOf(key) !== -1) {
......@@ -606,7 +610,7 @@ module.exports = (function() {
}
DAO.prototype.toJSON = function() {
return this.dataValues;
return this.get();
}
// private
......@@ -651,6 +655,12 @@ module.exports = (function() {
}
}
Utils._.each(this.attributes, function(key) {
if (!values.hasOwnProperty(key)) {
values[key] = undefined
}
})
this.set(values, options)
}
......
......@@ -700,7 +700,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('properly handles disparate field lists', function(done) {
it.only('properly handles disparate field lists', function(done) {
var self = this
, data = [{username: 'Peter', secretValue: '42' },
{username: 'Paul'},
......@@ -713,6 +713,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(users[0].secretValue).to.be.null
done()
})
}).on('sql', function (sql) {
console.log(sql)
})
})
......
......@@ -365,9 +365,11 @@ describe(Support.getTestDialectTeaser("Include"), function () {
ranks: function(callback) {
Rank.bulkCreate([
{name: 'Admin', canInvite: 1, canRemove: 1},
{name: 'Member', canInvite: 1}
{name: 'Member', canInvite: 1, canRemove: 0}
]).done(function () {
Rank.findAll().done(callback)
}).on('sql', function (sql) {
console.log(sql)
})
},
memberships: ['user', 'groups', 'ranks', function (callback, results) {
......@@ -545,7 +547,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
ranks: function(callback) {
Rank.bulkCreate([
{name: 'Admin', canInvite: 1, canRemove: 1},
{name: 'Member', canInvite: 1}
{name: 'Member', canInvite: 1, canRemove: 0}
]).done(function () {
Rank.findAll().done(callback)
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!