Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Lander
Full Stack JavaScript Techdegree Graduate 27,765 PointsTesting the validators
At random, I chose to mess with the release date values to see if I would get an error message. I didn't...
Movie.create({
title: "Captain America",
runtime: 115,
releaseDate: 73,
isAvailableOnVHS: true,
}),
Gives release date: releaseDate: 1970-01-01T00:00:00.073Z,
Read earlier that the date is coerced into a number anyway so this error won't be picked up. It made it into the database.
Movie.create({
title: "Captain America",
runtime: 115,
releaseDate: "0",
isAvailableOnVHS: true,
}),
Gives release date: releaseDate: 2000-01-01T00:00:00.000Z,
in the console. An error I imagine being made by data entry. Again, made it into the database without an error being thrown.
Movie.create({
title: "Captain America",
runtime: 115,
releaseDate: "Hello",
isAvailableOnVHS: true,
}),
Gives release date: releaseDate: Invalid Date,
Worth noting that it did not kick up a console error and still entered the 'invalid date' into the db.
Note these results only came back because of the console.log command, not error messages. I must have done something wrong as I can't imagine this would be useful.
1 Answer
Joseph Lander
Full Stack JavaScript Techdegree Graduate 27,765 PointsAnswer: If in doubt, check the next few videos first.
It appears these are setting data types and are indications of what we want to occur.
They are not validators trying to check for errors in the input.
The documentation goes as far as to discuss the difference: Sequelize: Validations and Constraints
Joseph Lander
Full Stack JavaScript Techdegree Graduate 27,765 PointsNow please feel free to go along with your days. Thanks
Joseph Lander
Full Stack JavaScript Techdegree Graduate 27,765 PointsJoseph Lander
Full Stack JavaScript Techdegree Graduate 27,765 PointsChecking back through my code I had made an assumption on syntax: my code:
releaseDate: { type: Sequelize.DATE, allowNull: false },
code in notes:
releaseDate: { type: Sequelize.DATEONLY, allowNull: false },
This time a random string did throw an error, however, it still updated the db.