Currently, I am utilizing Sails version 0.10.5 for my project. In the development process, I have established three models interconnected through associations. These models include a Candidate
, an Evaluator
, and a Rating
; where an evaluator provides ratings for a candidate. The Waterline associations are being used to automatically manage the foreign keys from the Rating
model to both Evaluator
and Candidate
.
Moreover, I have implemented Blueprint to handle all CRUD routing operations seamlessly for these models.
However, a dilemma arises when creating a new candidate via Blueprint with a URL like
http://localhost:1337/rating/create?rating=4&comment=Great&evaluator=3&candidate=2
. This results in triggering not only the expected CREATE action but also initiating two UPDATE actions. Subsequently, during these UPDATE requests, the foreign keys linking to each of the Candidate
and Evaluator
models are set, leading to unexpected behavior on the front-end of my application which struggles to interpret the data due to receiving an UPDATE event instead of the anticipated CREATE event.
If anyone has any recommendations or solutions to circumvent this complication, your assistance would be greatly appreciated!
Below are the details of the Waterline models employed:
/api/models/Candidate.js
:
module.exports = {
schema: true,
attributes: {
name: {
type: 'string',
required: true
},
status: {
type: 'string',
required: true
},
role: {
type: 'string',
required: true
},
ratings: {
collection: 'rating',
via: 'candidate'
}
}
};
/api/models/Evaluator.js
:
module.exports = {
schema: true,
attributes: {
name: {
type: 'string',
required: true
},
title: {
type: 'string',
required: true
},
role: {
type: 'string',
required: true
},
ratings: {
collection: 'rating',
via: 'evaluator'
}
}
};
/api/models/Rating.js
:
module.exports = {
schema: true,
attributes: {
rating: {
type: 'integer',
required: true
},
comment: {
type: 'string',
required: false
},
evaluator: {
model: 'evaluator',
required: true
},
candidate: {
model: 'candidate',
required: true
}
}
};