Skip to content

Commit

Permalink
fix: defaultValue is not accounted for in #108 (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed May 20, 2016
1 parent 71a1be6 commit ef8e779
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/packages/database/model/utils/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ function initializeProps(prototype, attributes, relationships) {

entries(attributes)
.reduce((hash, [key, { type, nullable, defaultValue }]) => {
if (/^(boolean|tinyint)$/.test(type)) {
defaultValue = Boolean(
typeof defaultValue === 'string' ?
parseInt(defaultValue, 10) : defaultValue
);
} else if (type === 'datetime' && typeof defaultValue === 'number') {
defaultValue = new Date(defaultValue);
}

hash[key] = {
get() {
const refs = refsFor(this);
Expand All @@ -94,7 +103,10 @@ function initializeProps(prototype, attributes, relationships) {
const { initialized, initialValues } = this;

if (/^(boolean|tinyint)$/.test(type)) {
nextValue = Boolean(nextValue);
nextValue = Boolean(
typeof nextValue === 'string' ?
parseInt(nextValue, 10) : nextValue
);
} else if (type === 'datetime' && typeof nextValue === 'number') {
nextValue = new Date(nextValue);
} else if (!nextValue && !nullable) {
Expand Down

0 comments on commit ef8e779

Please sign in to comment.