For experts familiar with sails.js: I have a Customers Model and to keep it simple lets say
/**
* Customers.js
*/
module.exports = {
attributes: {
firstName: { type: 'string' },
lastName: { type: 'string' }
}
};
IMPORTANT: There is also a CustomerHistory Model as shown below. Whenever a Customer is created or updated, a corresponding CustomerHistory record should also be inserted/created.
/**
* CustomerHistory.js
*/
module.exports = {
attributes: {
customer: { model: 'customer' },
firstName: { type: 'string' },
lastName: { type: 'string' },
modifiedAt: { type: 'datetime'}
}
};
OPTIONS within Sails.js:
Override or Create new Sails Blueprint actions (let's call it CreateWithHistory and UpdateWithHistory) which always inserts into CustomerHistory upon successful save into Customer. If this is the proposed solution, a code sample would help.
Create custom controller actions (let's call it CreateWithHistory and UpdateWithHistory) which always inserts into CustomerHistory upon successful save into Customer. If this is the proposed solution, a code sample would help as to how to chain 2 Model.create and Model.update with Model.create actions.
Create a custom Customers Model action to implicitly save into history on create or update. How to do this?