Open zaaack opened 7 years ago
Could you reformat your code or post it elsewhere? It's hard to follow it, because the indentation is broken and there's no spacing.
@vadimdemedes Sorry, added some annotations and a demo, hope it would be more clear.
Then I reallize SET action is not only used by outside, but also inside when query from the db (in the constructor), so I couldn't tell which action is triggered by user input or query from the db.
This is a good point, perhaps we'll need to introduce a specific action to dispatch on model initialization, like SEED
or INITIAL_SET
. @zaaack Any ideas for a better name?
@vadimdemedes I find out the feature I need is actual the virtual field feature in mongoose, and if I using another field name that doesn't exist in database, the problem solved.
But to solve the problem that there isn't a way to intercept query and persistence, I think we should let the models query from database using another action to initial, like INTERNAL_SET
, not just in constructor, since this could still be called by user.
I want to intercept get & set action to make the field value different in using & store, here are my code:
Then I reallize SET action is not only used by outside, but also inside when query from the db (in the constructor), so I couldn't tell which action is triggered by user input or query from the db.