Justin
Justin

Reputation: 155

Retrieving Attributes from Sequelize

Probably a very simple answer that I am just not finding. I have created a database of movies, I am able to find all movies simply enough with

    Movie.findAll().then(function(movies){

    movies.forEach(console.log);  
    });

What I want to do is be able to target the specific attributes of the movies as illustrated below, but I have no idea what to reference.

    Movie.findAll().then(function(movies){

    movies.forEach(console.log(THIS MOVIE TITLE));  
    });

Upvotes: 0

Views: 37

Answers (2)

Darshil Mehta
Darshil Mehta

Reputation: 122

There is a another way to get movie names.

You can specify the attribute names so you will get only those columns.

Movie.findAll({
  attributes: ['title']
}).then((movies) => {
});

By this, you get the array of an object which contains movie titles.

Upvotes: 0

LuisMendes535
LuisMendes535

Reputation: 536

Simply find the title of each movie inside the movies array.

Might be like this:

   Movie.findAll().then(function(movies){

   movies.forEach(movie => console.log(movie.title));  
   });

Upvotes: 1

Related Questions