-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Don't cast empty strings to
0
values in numeric Field
types
- Loading branch information
Showing
6 changed files
with
30 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,7 @@ | |
* @since 0.2.0 | ||
* @version 1.1.0 | ||
*/ | ||
var NumberField = Function.inherits('Alchemy.Field', function Number(schema, name, options) { | ||
Number.super.call(this, schema, name, options); | ||
}); | ||
const NumberField = Function.inherits('Alchemy.Field', 'Number'); | ||
|
||
/** | ||
* Set the datatype name | ||
|
@@ -25,14 +23,18 @@ NumberField.setDatatype('number'); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
* @version 0.4.1 | ||
* @version 1.4.0 | ||
* | ||
* @param {Mixed} value | ||
* @param {*} value | ||
* | ||
* @return {number} | ||
*/ | ||
NumberField.setMethod(function cast(value) { | ||
|
||
if (value === '') { | ||
value = null; | ||
} | ||
|
||
// Allow null | ||
if (value == null) { | ||
return value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,18 @@ const DecimalField = Function.inherits('Alchemy.Field.Number', 'Decimal'); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.3.20 | ||
* @version 1.3.20 | ||
* @version 1.4.0 | ||
* | ||
* @param {Mixed} value | ||
* | ||
* @return {Decimal} | ||
*/ | ||
DecimalField.setMethod(function cast(value) { | ||
|
||
if (value === '') { | ||
value = null; | ||
} | ||
|
||
// Allow null | ||
if (value == null) { | ||
return value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,14 +29,18 @@ BigIntField.setDatatype('bigint'); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.3.6 | ||
* @version 1.3.6 | ||
* @version 1.4.0 | ||
* | ||
* @param {Mixed} value | ||
* | ||
* @return {BigInt} | ||
*/ | ||
BigIntField.setMethod(function cast(value) { | ||
|
||
if (value === '') { | ||
value = null; | ||
} | ||
|
||
// Allow null | ||
if (value == null) { | ||
return value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,18 @@ const FixedDecimalField = Function.inherits('Alchemy.Field.Decimal', function Fi | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.3.20 | ||
* @version 1.3.20 | ||
* @version 1.4.0 | ||
* | ||
* @param {Mixed} value | ||
* | ||
* @return {Decimal} | ||
*/ | ||
FixedDecimalField.setMethod(function cast(value) { | ||
|
||
if (value === '') { | ||
value = null; | ||
} | ||
|
||
// Allow null | ||
if (value == null) { | ||
return value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,25 @@ | |
* @since 1.1.0 | ||
* @version 1.1.0 | ||
*/ | ||
var IntegerField = Function.inherits('Alchemy.Field.Number', function Integer(schema, name, options) { | ||
Integer.super.call(this, schema, name, options); | ||
}); | ||
const IntegerField = Function.inherits('Alchemy.Field.Number', 'Integer'); | ||
|
||
/** | ||
* Cast the given value to this field's type | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.1.0 | ||
* @version 1.1.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {Mixed} value | ||
* @param {*} value | ||
* | ||
* @return {number} | ||
*/ | ||
IntegerField.setMethod(function cast(value) { | ||
|
||
if (value === '') { | ||
value = null; | ||
} | ||
|
||
// Allow null | ||
if (value == null) { | ||
return value; | ||
|