Skip to content

Commit

Permalink
fix: accept timestamps in snake case (#221)
Browse files Browse the repository at this point in the history
do not add default timestamps if timestamps in snake case exists already
  • Loading branch information
cyjake authored Nov 1, 2021
1 parent b0ca01a commit a2a7029
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/bone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,9 @@ class Bone {
const names = [ 'createdAt', 'updatedAt' ];
if (paranoid) names.push('deletedAt');
for (const name of names) {
if (!attributes.hasOwnProperty(name)) attributes[name] = DataTypes.DATE;
if (!attributes[name] && !attributes[snakeCase(name)]) {
attributes[name] = DataTypes.DATE;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/unit/bone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ describe('=> Bone', function() {
assert.equal(User.attributes.updatedAt, undefined);
assert.equal(User.attributes.deletedAt, undefined);
});

it('should not append timestamps if underscored', async function() {
class User extends Bone {}
User.init({ name: STRING, created_at: DATE, updated_at: DATE });
assert.equal(User.attributes.createdAt, undefined);
assert.equal(User.attributes.updatedAt, undefined);
assert.equal(User.attributes.deletedAt, undefined);
assert.ok(User.attributes.created_at);
assert.ok(User.attributes.updated_at);
});
});

describe('=> Bone.load()', function() {
Expand Down

0 comments on commit a2a7029

Please sign in to comment.