Closed ZealJared closed 8 years ago
Hey Man! (apologies for the late reply) Glad that you like it. You can update the module to the latest version "0.3.2" and keep just the code below, it will do all the work you want:
let userGroup = new T.tayr('userGroup', {
dateCreated: new Date()
})
let user = new T.tayr('user', {
firstName: 'Default',
lastName: 'User'
})
user.setParent(userGroup).then(function () {
console.log('User: ' + user.id + ' belongs to group: ' + userGroup.id)
})
If that doesn't fix your problem, let me know what error do you get
You switched to promises! That's awesome.
I'm still getting an error on the dateCreated
field. When I console.log(query.sql)
out of mysql
module's Connection.prototype.query()
I get:
...
CREATE TABLE IF NOT EXISTS userGroup ( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY )
...
ALTER TABLE userGroup ADD dateCreated INT
...
INSERT INTO userGroup SET dateCreated = 1469547666197 ON DUPLICATE KEY UPDATE dateCreated = 1469547666197
Then I get the error:
Error: ER_WARN_DATA_OUT_OF_RANGE: Out of range value for column 'dateCreated' at row 1
So this is because a javascript Date()
won't fit in an INT
field, but from looking at your code, it seems like getDataType()
should catch the Date
object (with typeof
and instanceof
) and return a field data type of BIGINT
.
In getDataType(v)
, if I console.log
v
along with the corresponding data type, I get:
2016-07-26T16:03:18.906Z 'BIGINT'
1469548998906 'INT'
So it appears getDataType
is being called twice. The first time dateCreated
is recognized as a Date
object, the second time as a Number
.
I notice mendValue
has this line: if (v instanceof Date) return v.getTime()
which could have the effect of converting a Date
object to a Number
. Do you think this is where the issue might be?
I Added this line in getDataType:
if (v > 2147483647) return "BIGINT";
does this solve the problem ?
Yes! Thank you so much. Keep up the good work!
You're welcome! And thank you too for your report and your encouragement! Don't hesitate to contribute
Let me just say, I love this module! That being said, I'm having a hard time tracking down why the code below doesn't create a 'BIGINT' field for 'dateCreated'
Any ideas?