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

Databases Find Entries

Erland Van Olmen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Erland Van Olmen
Full Stack JavaScript Techdegree Graduate 17,825 Points

Why are we passing the "article" object to res.render() in the "/:id" GET route instead of "article.dataValues" ?

when I console.log the retrieved "article" I get a complex object like this:

Article {
  dataValues: {
    id: 1,
    title: 'Dit is de titel van het eerste nieuwe artikel',
    author: 'Mr Erlando',
    body: 'Dit is dus de body van het eerste nieuwe artikel :)',
    createdAt: 2021-06-25T11:45:10.601Z,
    updatedAt: 2021-06-25T11:45:10.601Z
  },
  _previousDataValues: {
    id: 1,
    title: 'Dit is de titel van het eerste nieuwe artikel',
    author: 'Mr Erlando',
    body: 'Dit is dus de body van het eerste nieuwe artikel :)',
    createdAt: 2021-06-25T11:45:10.601Z,
    updatedAt: 2021-06-25T11:45:10.601Z
  },
  _changed: {},
  _modelOptions: {
    timestamps: true,
    validate: {},
    freezeTableName: false,
    underscored: false,
    paranoid: false,
    rejectOnEmpty: false,
    whereCollection: { id: '1' },
    schema: null,
    schemaDelimiter: '',
    defaultScope: {},
    scopes: {},
    indexes: [],
    name: { plural: 'Articles', singular: 'Article' },
    omitNull: false,
    sequelize: Sequelize {
      options: [Object],
      config: [Object],
      dialect: [SqliteDialect],
      queryInterface: [QueryInterface],
      models: [Object],
      modelManager: [ModelManager],
      connectionManager: [ConnectionManager],
      importCache: [Object]
    },
    hooks: {}
  },
  _options: {
    isNewRecord: false,
    _schema: null,
    _schemaDelimiter: '',
    raw: true,
    attributes: [ 'id', 'title', 'author', 'body', 'createdAt', 'updatedAt' ]
  },
  isNewRecord: false
}

So naturally, I thought we would need to pass article.dataValues here, however this is not the case. I don't understand why something like "article.title" even works, as the article object does not have a key called "title". That value/key pair sits inside article.dataValues. What's up with that?

1 Answer

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Hi Erland Van Olmen , although the answer is very late but if still need some help. Actually Instances get the default values, even though a lot of things are attached to them. Read Here. It's the link to there official webpage, explaining the issue. I Hope it will be helpful.