Sails v1.x stores empty properties in database mongoDb, when POST api call is made with request having few properties only from actual model defined in sails model, such properties which are not available in request is saved with empty values in database collection which was not the case in sails v0.12 Since I have migrated project from sails v0.12 to sails v1.x, I am facing this issue which is leading to code breakage on api response.
I am using JOI library to validate the request properties and below is the data that is being sent to <ModelName>.create(topic).fetch()
topic = {
published: false,
closed: false,
name: 'Topic G -01',
communityId: '57d640b3-cda6-4703-8080-2ef604de2086',
activityId: '23ef04f4-699d-47c7-94ad-3fb5b1c18889',
createdByUserId: '3cc6dddd-9425-42b8-83fc-4ba3f068128d',
board: '5f7cc128c2380d00172225ee'
}
Data getting saved in database collection as below:
{
_id: ObjectId("61c9d4ec5ceca05c4b0016cb"),
published: false,
closed: false,
name: 'Topic G -01',
communityId: '57d640b3-cda6-4703-8080-2ef604de2086',
activityId: '23ef04f4-699d-47c7-94ad-3fb5b1c18889',
createdByUserId: '3cc6dddd-9425-42b8-83fc-4ba3f068128d',
board: '5f7cc128c2380d00172225ee',
createdAt: '2021-12-28T16:11:07.229Z',
updatedAt: '2021-12-28T16:11:07.229Z',
description: '',
content: null,
official: false,
locked: false,
singleResponses: false,
responseTierLimit: 0,
deleteOwnResponses: false,
showQuantResults: false,
probeQuantResponse: false,
ratingSystem: '',
responseVisibility: '',
allowParticipantQuestions: false,
qIndexVisibility: false,
disablePostReplies: false,
publishedAt: null,
questionIds: null,
updatedByUserId: '',
includedRoles: null,
}
However in sails v0.12, on the contrary it used to store as below:
{
_id: ObjectId("61c9d4ec5ceca05c4b0016cb"),
published: false,
closed: false,
name: 'Topic G -01',
communityId: '57d640b3-cda6-4703-8080-2ef604de2086',
activityId: '23ef04f4-699d-47c7-94ad-3fb5b1c18889',
createdByUserId: '3cc6dddd-9425-42b8-83fc-4ba3f068128d',
board: '5f7cc128c2380d00172225ee',
createdAt: '2021-12-28T16:11:07.229Z',
updatedAt: '2021-12-28T16:11:07.229Z',
}