I have an existing WP database that I am trying utilize to create an API using node and sequelize. I'd like to limit the fields which are returned in the query as WP adds a ton of fields I don't want to display in the API. From what I understood, when I define the model, the fields I used, should be the only ones which are returned. It appears though, that the query created is simply using '*'. Also, the aliasing of the field names, do not seem to be happening either. Below is my model.
module.exports = function(sequelize, DataTypes) {
var Campground = sequelize.define('Campground', {
ID: {
type: DataTypes.INTEGER,
primaryKey: true
},
Name: {
type: DataTypes.STRING,
field: 'post_title'
},
Description: {
type: DataTypes.TEXT,
field: 'post_content'
}
}, {
tableName: 'wp_posts',
timestamps: false,
defaultScope: {
where: {
post_type: 'campgrounds'
}
},
classMethods: {
associate: function(models) {
Campground.hasMany(models.Meta, {
as: 'Park_Info',
foreignKey: 'post_id'
})
Campground.hasOne(models.Locator, {
foreignKey: 'post_id'
})
}
}
})
return Campground
}
@MickHansen's comment was the answer I was looking for. See https://github.com/sequelize/sequelize/wiki/API-Reference-Model#findAll