I am new to SailsJS
and using it for an application and facing some issues with queries while deleting a Project
Model
Project Model:
name: {
type: 'string',
required: true
},
deletedAt: {
type: 'datetime'
},
deletedBy: {
model: 'User',
}
User Model:
name: {
type: 'string',
required: true
},
email: {
type: 'string',
required: true
}
On creating a project, Sails automatically fills in data for createdAt and updatedAt and I am filling in data for Project Name
On deleting a project, I need to do a soft-delete, where In I will be setting deletedAt
value and deletedBy
values.
On getting list of all projects, It should not get deleted projects.
One way I thought of was to get all projects using query:
Project.find(function (err, projList) {
..
}
and then for each project do a check as follows:
if (project.hasOwnProperty('deletedBy') && project.deletedBy != null) {
//Dont include this in list
}
Is there any way, Instead of I manually checking for deleted projects, Can it be done using queries? i.e. Omitting all deleted projects.
Thanks in Advance.