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 trial

JavaScript Using SQL ORMs with Node.js Defining Models Defining Models Review

Data type that prevents empty strings when creating a model instance?

I'm stuck on this question. Sequelize.STRING is obviously not sufficient, but adding on allowNull: false, validate with notNull/notEmpty is not working either. Feel as though I've tried everything. Help, please?

The question is: Complete the code below by adding the data type that prevents empty strings when creating a model instance:

Car.init({
  Make: {
    type: Sequelize.<FILL IN ANSWER>
  },
}, { sequelize });

2 Answers

Hi Amy,

I guess I understand why you feel that STRING would not (or should not) be sufficient, but Sequelize.STRING is indeed the correct answer.

Yes, you would need to add validation. But the Datatype that would make that validation relevant to a string is STRING. Adding a notEmpty validation to a Sequelize.BOOLEAN datatype (for example) would do nothing with regards to strings (assuming that’s a valid validator for the BOOLEAN datatype). So even though Sequelize.STRING isn’t enough code to prevent your user from inputting an empty string, it is the only Datatype that prevents empty strings as it’s the only one that requires a string.

I hope that makes sense.

Thank you! It worked. I was so certain that I had tried that. Appreciate your answer!