Generates one or several entity key(s) for the Model. This method accepts the following arguments (all arguments are optional):
MyModel.key(/* {string | { id: string|number } | { name: string }} It can also be an Array of ids to generate */ <id>, /* {Array} -- optional. ex: ['ParentEntity', 1234 ] */ <ancestors>, /* {string} -- optional. A specific namespace */ <namespace>)
Example:
constUser=require('./user.model');// Providing a Key "id"constentityKey=User.key({ id:123 });// "string" id will automatically be converted to integerconstentityKey=User.key({ id:'123' });// You can also provide a key "name"constentityKey=User.key({ name:'myEntity' });// or passing the string name directlyconstentityKey=User.key('myEntity');// with ancestors and namespaceconstentityKey=User.key({ id:123 }, ['Parent','keyname'],'dev.domain.com');// with an Array of idsconstentityKeys=User.key([{ id:'123' },'myEntity']);console.log(entityKeys.length); // 2