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 trialHenry Spock
20,615 PointsSetting defaultValue for type:Sequelize.BOOLEAN does nothing.
I've tried every permutation I can think of (that isn't throwing an error) and I can't get any behavior other than an empty field (with allowNull also set to false.)
Currently:
on movie.js:
isAvailableOnPrime: { type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false}
on app.js:
const movie1 = await Movie.create({
title: 'Robin Hood',
releaseDate: '1938-05-14',
director1: 'Michael Curtiz',
director2: 'William Keighley',
runtime: 102,
isAvailableOnPrime: '',
});
In BD Browser:
1 Robin Hood 1938-05-14 Michael Curtiz William Keighley 102
Value "false" should show up after the runtime (102).
2 Answers
Jason Larson
8,361 PointsIt's not showing up because you've set isAvailableOnPrime: ''
. Since you're setting this value, it's not using the defaultValue. Leave that out of your movie declaration and it should work:
const movie1 = await Movie.create({
title: 'Robin Hood',
releaseDate: '1938-05-14',
director1: 'Michael Curtiz',
director2: 'William Keighley',
runtime: 102,
});
Henry Spock
20,615 PointsAH - I see what you mean. I was basically setting the value twice, and whatever the value was set to in the model overrides the default. Thanks - I'm getting expected behavior now!
Henry Spock
20,615 PointsHenry Spock
20,615 PointsWhen I set it to nothing, I get a syntax error for the comma. SyntaxError: Unexpected token ','
When I remove the comma, I get a syntax error for the subsequent bracket. SyntaxError: Unexpected token '}'
The '' is there currently just to prevent a syntax error as I proceeded on to the rest of the course.
Jason Larson
8,361 PointsJason Larson
8,361 PointsI understand. It's a bit non-intuitive, but if you don't specify it at all in the declaration (as in the example I gave), the script will add it with the default value. If you list it, it is expecting some sort of value, so you get an error, or the value you give it overrides the default value.