You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
Probably easiest way to do this without major refactoring is to use the existing save mechanism.
Currently save client passes a "validate" param to the server which is either truthy/falsy.
What we can do is pass :validate_only in the valid param, and call (from the client) the save server side method (inisomorphic_base). This will run the whole save process which is wrapped in a transaction. At the bottom of the save method, it checks the save parameter. Right at that point it should first check the validate parameter and if it is :validate_only then raise and internally defined error class called ValidRollback. Then catch this error outside the transaction block, and report that the record is valid.
Likewise if an error is raised, then right at the normal rescue, we need to check and see if if the exception is because of an invalid record, capture what ever is invalid and report this back to the client.
summary of changes:
client side:
# instance methods module:defvalid?(&block)@backing_record.valid?(&block)enddefinvalid?(&block)ifblockvalid?{ |valid| block.call !valid}elsevalid?.then{ |valid| !valid}# I think.... maybe its Promise.new(!valid)endend# isomorphic methods:# add this method at about # line 331defvalid?(validate, &block)models,associations,backing_records=self.class.gather_records([self],force,self)backing_records.each{ |id,record| record.saving!}promise=Promise.newHTTP.post(`window.ReactiveRecordEnginePath`+"/save",payload: {json: {models: models,associations: associations,validate: :validate_only}.to_json}).thendo |response|
beginresponse.json[:models]=response.json[:saved_models].collectdo |item|
backing_records[item[0]].ar_instanceendresponse.json[:saved_models].eachdo | item |
backing_records[item[0]].errors!item[3]endyieldresponse.json[:valid]ifblockpromise.resolveresponse.json[:valid]backing_records.each{ |id,record| record.saved!}endpromiseend# approx line 538:# add this check:ifvalidate == "validate_only"# I think this is a string at this pointRaiseValidationRollbackelsifsave{success: true,saved_models: saved_models}elsevectors.each{ |vector,model| model.reloadunlessmodel.nil?ormodel.new_record?ormodel.frozen?}vectorsend# approx line 551:rescueValidationRollback{valid: true,valid_models: saved_models}rescueException=>eife.message == ""Could not saveallmodels" && validate == "validate_only"
{valid: false,valid_models: saved_models}else
...carryon
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Probably easiest way to do this without major refactoring is to use the existing
save
mechanism.Currently save client passes a "validate" param to the server which is either truthy/falsy.
What we can do is pass
:validate_only
in thevalid
param, and call (from the client) thesave
server side method (inisomorphic_base
). This will run the whole save process which is wrapped in a transaction. At the bottom of the save method, it checks thesave
parameter. Right at that point it should first check thevalidate
parameter and if it is:validate_only
then raise and internally defined error class calledValidRollback
. Then catch this error outside the transaction block, and report that the record is valid.Likewise if an error is raised, then right at the normal rescue, we need to check and see if if the exception is because of an invalid record, capture what ever is invalid and report this back to the client.
summary of changes:
client side:
The text was updated successfully, but these errors were encountered: