Type mapping dynamically.

13 views
Skip to first unread message

Fernando Cagale

unread,
May 8, 2015, 10:12:18 AM5/8/15
to sequ...@googlegroups.com
Hello,

I wonder if you can take the kind of property dynamically, if STRING, INTEGER, DATE etc. Why do I have to put together a dinamicamante query.

   var User = sequelize.define ('User', {
     name
: {
       type
: DataTypes.STRING (20)
     
},
     lastName
: {
       type
: DataTypes.STRING (20)
     
},
     password
: {
     
},
     email
: {
       type
: DataTypes.STRING (40)
     
}
     
....



The name I can get through:

for (var prop in User.attributes) {
   console
.log (prop);
 
}

... name
... lastName
... password

Mick Hansen

unread,
May 8, 2015, 10:43:56 AM5/8/15
to Fernando Cagale, sequ...@googlegroups.com
Hey there,

I'm not quite sure i've ever seen the word dinamicamante before.
Are you saying we should infer the data type from the attribute name? Not sure that would be at all feasible.
--
Mick Hansen
@mhansendev
mhansen.io

Fernando Cagale

unread,
May 8, 2015, 10:50:11 AM5/8/15
to sequ...@googlegroups.com, fernando...@gmail.com
Oops!

It would be dynamically the translator google translated wrong!

Then I would somehow know what kind of property, from sequelize object, in which case it would be User.

Thank you.

Mick Hansen

unread,
May 8, 2015, 10:57:47 AM5/8/15
to Fernando Cagale, sequ...@googlegroups.com
Ah,

You can use Model.rawAttributes[key].type
Reply all
Reply to author
Forward
0 new messages