По умолчанию паруса будут генерировать первичный ключ id
, если вы его не указали.
Если вы хотите, чтобы пользовательские данные использовались в качестве первичного ключа, вы можете переопределить атрибут id
в модели и задать a columnName
id: {
type: 'string',
columnName: 'email_address',
required: true
}
Затем вы можете найти запись, используя:
await User.find({ id: req.param('emailAddress' });
Ссылка
В вашем случае это выглядит как каждый archived
имеет personalInfo
. Так что это one to one
со стороны archived
, но one to many
со стороны personalInfo
. Чтобы смоделировать эти отношения, в парусах вы можете сделать что-то вроде:
personalInfo. js
module.exports = {
attributes: {
fullName:{
type: 'string',
required: true
},
phone:{
type: 'string',
required: true
},
location:{
type: 'string',
required: true
},
age:{
type: 'integer',
required: true
},
email:{
type: 'string',
required: true
},
gender:{
type: 'string',
required: true
},
userId:{
type: 'integer',
required: true,
},
archives: {
collection: 'archived',
via: 'info'
}
},
};
в архиве. js
module.exports = {
attributes: {
userId: {
type: 'number',
required: true,
//unique: true,
},
comment:{
type: 'string',
required: true
},
createdBy:{
type: 'number',
required: true
},
info: {
model: 'personalinfo' // sails works with small cases internally for models
}
},
};
Как только вы это сделаете, создание archive
будет:
await Archive.create({
...
// Set the User's Primary Key to associate the info with the archive.
info: 123
});
Теперь вы наконец-то сможете заполнить info
во время запроса.
var archived = Archived.find().populate('info');