virtual attributes are always return by model
See original GitHub issuevar pinyin = require('pinyin');
module.exports = function(sequelize, DataTypes) {
var moneyType = sequelize.options.dialect === 'mssql' ? 'MONEY' : DataTypes.INTEGER;
return sequelize.define('Pt', {
usertype:{
type:DataTypes.VIRTUAL,
get(){
return '0'
}
},
pinyin:{
type:DataTypes.VIRTUAL,
scopes:['user'],
get(){
return pinyin(this.getDataValue('TX_Name'),{
segment:false,
style:pinyin.STYLE_NORMAL
}).join('')
}
},
ID_User: {
primaryKey: true,
type: DataTypes.STRING,
allowNull: false
},
TX_Name: {
type: DataTypes.STRING,
allowNull: true
},
DT_Birth: {
type: DataTypes.DATE,
get:function(){
var d = this.getDataValue('DT_Birth')
return d ? d.toLocaleString() : d;
},
allowNull: true
},
TX_IC: {
type: DataTypes.STRING,
allowNull: true
},
TX_IMG: {
type: DataTypes.STRING,
allowNull: true
},
TX_Location: {
type: DataTypes.STRING,
allowNull: true
},
TX_Signature: {
type: DataTypes.STRING,
allowNull: true
},
TX_Username: {
type: DataTypes.STRING,
allowNull: false
},
TX_Password: {
type: DataTypes.STRING,
allowNull: true
},
TX_Contact: {
type: DataTypes.STRING,
allowNull: true
},
TX_QQ: {
type: DataTypes.STRING,
allowNull: true
},
TX_WeChat: {
type: DataTypes.STRING,
allowNull: true
},
TX_QR: {
type: DataTypes.STRING,
allowNull: true
},
DT_Delivery: {
type: DataTypes.DATE,
get:function(){
var d = this.getDataValue('DT_Delivery')
return d ? d.toLocaleString() : d;
},
allowNull: true
},
TX_Name2: {
type: DataTypes.STRING,
allowNull: true
},
TX_Contact2: {
type: DataTypes.STRING,
allowNull: true
},
MN_Credit: {
type: moneyType,
allowNull: true
},
MN_Deposit: {
type: moneyType,
allowNull: true
},
}, {
defaultScope: {
attributes: { exclude: ['TX_Password'] }
},
scopes:{
'user':{
attributes:['ID_User','TX_Name','DT_Birth','TX_IC','TX_IMG','TX_Location','TX_Signature','TX_Username','TX_Password','TX_QR','TX_Contact','TX_QQ','TX_WeChat']
}
},
updatedAt:'DTTM_Updated',
createdAt:'DTTM_Created',
tableName: 'T_Pt',
freezeTableName: true
});
};
the attributes usertype and pinyin are always return where i findOne/findAll event i use model.scope(‘xxx’)
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:17 (1 by maintainers)
Top Results From Across the Web
Virtual attributes in rails model - ruby - Stack Overflow
Usually virtual attributes are used when some attribute is not stored directly in the DB, but can be converted from and to an...
Read more >Can I modify the display value of a virtual attribute? | Clarity
I am adding a couple virtual attributes to display data from the master object (project) into a sub-object (status reports).
Read more >Column Aliases & Virtual Attributes
Is it possible to select a column alias and have it automatically assigned to the corresponding model object attribute. I'm assuming
Read more >Mongoose Virtuals
Virtuals are properties on Mongoose documents. If you use the lean option, that means your queries return POJOs rather than full Mongoose documents....
Read more >Understanding Virtual Attributes and get/set methods | Wiki
With this getter function defined, $model->fullname automatically calls the function and returns the value as if it were a real attribute: this ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any update on this issue ? Still not solved in release
v5.21.3
…This is still an issue.