Open NejcHorvat opened 8 years ago
@NejcHorvat could you explain more? When you save is the new object to returned in the callback for save?
@mcdonnelldean yes. When you save the store would return the saved object so that the entity could be updated with any mutated values.
@NejcHorvat I'm not understanding the requirement. Could you explain it more. Are you asking to have an event
or way to update an entity you have locally in cases where something externally (service or database) have updated it?
@mcdonnelldean what @NejcHorvat means is this:
table SUPPLIER (
ID long not null auto_increment(1,1)
FLAG bit not null default(true)
NAME string
TAX_NUMBER string
TAX_CODE string
)
before insert trigger on SUPPLIER (
if (new.TAX_NUMBER != NULL and new.TAX_CODE == null) {
new.TAX_CODE = 'A'
}
)
seneca.make('supplier').data$({name: 'Company', taxNumber: '123-ABC'})
.save$(function (err, entity) {
assert(entity.id > 0)
assert.strictEqual(entity.flag, true)
assert.equals(entity.taxCode, 'A')
});
I'm sorry for not replying to you @mcdonnelldean, had a few super busy months and the project I had this requirement for had to go on the back burner. What @indr said is correct. This is what I had in mind.
@indr @NejcHorvat Is this not what it does already?
@mcdonnelldean I don't know. Didn't look at the source or test it. It also isn't the seneca-entity
s responsibility to read from a data source. The save$
method seams to send the pattern role:entity,cmd:save,ent:{}
and passes the same callback (https://github.com/senecajs/seneca-entity/blob/master/lib/make_entity.js#L155). I guess this will be handled by the stores?
@NejcHorvat What store did you use?
the returned entity (via callback) should reflect whatever is in the database - this is store implementation dependent however - adding an issue to the store test suite https://github.com/senecajs/seneca-store-test/issues/48
Would it be possible to introduce a mechanism for updating the entity with a result from the store that saved it?
Three use cases:
Postgres example would be just adding RETURN * at the end of a save / update. The returned item could be appended to the result and applied on the entity.
What would be the preferred approach for this? I am willing to create a pull for this but would like to hear your opinion on this and maybe get a few pointers or thoughts.