Unlike the previous question I asked here, it is connected and I really wanted to connect it.
I tried very hard to find out how I can get the name of the model (personality) or the model "class" (set in sails.models) of the record. So, given the record waterline, how can I find out her model name or class?
Example (of course, here I know what the model is User, but this is an example):
User.findOne(1).exec(function(err, record) {
getTheModelSomehow(record);
});
I tried to access it with record.constructor, but it is not User, and I could not find any property on recordby exposing the object to the pseudo-class of the model or the name of the recording model.
UPDATE:
To clarify, I need a function for which I will give ANY record, and which will return the model of this record either as the model name or an object of the model pseudo-class, as in the namespace sails.models.
modelForRecord(record) // => 'user' (or whatever string being the name of the record model)
or
modelForRecord(record) // => User (or whatever record model)
source
share