hyperstack-org / hyperstack-org/hyperstack

Handle saving while related record is loading

Đang mở
#321 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
JavaScript
Star
538
Fork
41
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Currently if an record or one of its relationships is loading when you try to save the record, an error will be raised.

This is due to the following lines in the `gather_records` method:

```ruby
if record.id.loading? and record_being_saved
raise "Attempt to save a model while it or an associated model is still loading: model being saved: #{record_being_saved.model}:#{record_being_saved.id}#{', associated model: '+record.model.to_s if record != record_being_saved}"
end
```

Instead of aborting this way the whole activity needs to be wrapped in a promise, that will wait until such records are loaded, and then continue. Note that putting this into a promise is not a problem as the `save` operation is already asynchronous (and returns a promise)

Probably a full rewrite of the `gather_records` and associated methods would be best, HOWEVER, this is real tails case, and so at least in the short term a "brute" force approach where any `record.id` that is loading is put into a list, and then we wait for all the items to be loaded, and then retry the whole save.

Currently there is no one work-around. What you need to do is have code that waits until the related things are loaded before, proceeding with the save.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.