Basically, given an instance or a model, I would like to a) Know if a primary key exists b) know the name of that field(s)
Thanks to Soheil Jadidian's comment; the following snippet returns an array of primary keys found. Thus, it works with composite keys as well.
Model.describe().then(function (schema) {
return Object.keys(schema).filter(function(field){
return schema[field].primaryKey;
});
}).tap(console.log);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With