Implementation of patchById#910
Conversation
11c1f00 to
5437808
Compare
|
|
||
| var context = { | ||
| Model: Model, | ||
| instanceId: id, |
There was a problem hiding this comment.
I am proposing to use the same context as we have for updateAll:
- Model
- where
- data
- hookState
- options
Note that instance id can be extracted from the where clause, see https://github.com/strongloop/loopback/blob/4cd84dcd8af5f4f90ff62f506a6bf49e6fc2036b/lib/persisted-model.js#L1508-L1518.
We can eventually put getIdFromWhereByModelId into a public LoopBack API if there is enough demand.
This is the reason why I am reluctant to add instanceId: when we have both where and instanceId, and a hook changes one of these properties only, it's not clear which one takes precedence. I suppose we could make instanceId read-only, although the downside is that Object.defineProperty incurs performance penalty :(
|
@Amir-61 one more thought to consider: eventually, I think it will be good to refactor I am proposing the following:
module.exports = function patchById(...) {
// ...
};
DataAccessObject.patchById = require('./dao/patch-by-id');
Thoughts? |
|
The refactor we talked about was smaller in scope but the ideas you're proposing are in line with the steps after. As you say, we might as well get it started now since you're already working on it. Also, the way to align tests into suites by feature is also what I had in mind. |
3c7f13e to
a797f51
Compare
246d1ee to
c995f69
Compare
| var assert = require('assert'); | ||
| var BaseModel = require('./model'); | ||
| var debug = require('debug')('loopback:dao'); | ||
| DataAccessObject.patchById = require('./patch-by-id'); |
There was a problem hiding this comment.
Please move the new file under a new folder, i.e. dao/patch-by-id.js.
I just managed to do very initial implementation of
patchByIdand opened this PR to have some discussion to see whether we agree about thecontextof different hooks considering the fact that in this method you would not have access toinstanceandcurrentInstance.Apart from this I need to write a bunch of tests to verify that
patchByIdworks well and their operations hooks are triggered in the right way.@bajtos PTAL :-)
Connect to https://github.com/strongloop-internal/scrum-loopback/issues/752
Thanks!