What's the standard pattern for ember-data validations? (invalid state, becameInvalid…)

前端 未结 5 746
囚心锁ツ
囚心锁ツ 2021-01-31 05:59

I\'ve kinda been struggling with this for some time; let\'s see if somebody can help me out.

Although it\'s not explicitly said in the Readme, ember-data provides somewh

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 06:11

    I tried Javier's answer, but I get "Invalid Path" when doing any record.set(...) with the record in invalid state. What I found worked was:

    // with the record in invalid state
    record.send('becameValid');
    record.set('someProperty', 'a valid value');
    App.store.commit();
    

    Alternatively, it seems that if I call record.get(...) first then subsequent record.set(...) calls work. This is probably a bug. But the above work-around will work in general for being able to re-commit the same record even without changing any properties. (Of course, if the properties are still invalid it will just fail again.)

提交回复
热议问题