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

Commit b73d1f91 by Mick Hansen

Merge pull request #1888 from mohlman3/bugfix/field_mapping_same_name

Allow field names to be same as property name
2 parents ff4b7850 09437fbe
Showing with 34 additions and 3 deletions
...@@ -555,7 +555,7 @@ module.exports = (function() { ...@@ -555,7 +555,7 @@ module.exports = (function() {
} }
// Field name mapping // Field name mapping
if (self.Model.rawAttributes[attr].field) { if (self.Model.rawAttributes[attr].field && self.Model.rawAttributes[attr].field !== attr) {
values[self.Model.rawAttributes[attr].field] = values[attr]; values[self.Model.rawAttributes[attr].field] = values[attr];
delete values[attr]; delete values[attr];
} }
......
...@@ -63,7 +63,11 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -63,7 +63,11 @@ describe(Support.getTestDialectTeaser("Model"), function () {
text: { text: {
type: DataTypes.STRING, type: DataTypes.STRING,
field: 'comment_text' field: 'comment_text'
} },
notes: {
type: DataTypes.STRING,
field: 'notes'
}
}, { }, {
tableName: 'comments', tableName: 'comments',
timestamps: false timestamps: false
...@@ -120,7 +124,10 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -120,7 +124,10 @@ describe(Support.getTestDialectTeaser("Model"), function () {
}, },
comment_text: { comment_text: {
type: DataTypes.STRING type: DataTypes.STRING
} },
notes: {
type: DataTypes.STRING
}
}) })
]); ]);
}); });
...@@ -247,6 +254,30 @@ describe(Support.getTestDialectTeaser("Model"), function () { ...@@ -247,6 +254,30 @@ describe(Support.getTestDialectTeaser("Model"), function () {
}); });
}); });
}); });
it('field names that are the same as property names should create, update, and read correctly', function () {
var self = this;
return this.Comment.create({
notes: 'Foobar'
}).then(function () {
return self.Comment.find({
limit: 1
});
}).then(function (comment) {
expect(comment.get('notes')).to.equal('Foobar');
return comment.updateAttributes({
notes: 'Barfoo'
});
}).then(function () {
return self.Comment.find({
limit: 1
});
}).then(function (comment) {
expect(comment.get('notes')).to.equal('Barfoo');
});
});
}); });
describe('types', function () { describe('types', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!