Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 526 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use an include with attributes with sequelize?

#1
Any idea how to use an include with attributes (when you need to include only specific fields of the included table) with sequelize?

Currently I have this (but it doesn't work as expected):

var attributes = ['id', 'name', 'bar.version', ['bar.last_modified', 'changed']];
foo.findAll({
where : where,
attributes : attributes,
include : [bar]
}).success(function (result) { ...
Reply

#2
Something like this should work

foo.findAll({
where : where,
attributes : attributes,
include : [{ model: bar, attributes: attributes}]
}).success(function (result) {


Reply

#3
We can do something like that for exclude or include specific attribute with sequelize in Node.js.

Payment.findAll({
where: {
DairyId: req.query.dairyid
},
attributes: {
exclude: ['createdAt', 'updatedAt']
},
include: {
model: Customer,
attributes:['customerName', 'phoneNumber']
}
})
Reply

#4
Use the select without hyphen (-) only blank spaces like this.

Model.find().select('attr1 attr2 attr3')
Reply

#5
Course.findAll({where: {
status:responseCode.STATUS_ACTIVE
}, attributes:['id','course_title','course_slug','age_group','image','class_duration','no_of_classes','is_course_upcoming'],
order:[['is_sorting','ASC']],
include:{model:Section,attributes:['id','title','course_id','start_date','end_date']},
}).then(course_detail =>{
result(null,course_detail);
}).catch(err =>{
console.log(err)
});
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through