makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Add `mutations_from_database` copy to cast. #133

Closed unrooty-infinum closed 3 years ago

unrooty-infinum commented 3 years ago

This PR adds @mutations_from_database instance variable copy to ActiveType.cast_record method. It's needed because change method from ActiveSupport uses this instance variable to carefully handle model changes.

F.e. now I have a situation when model setter is overridden by ActiveType gem. Then after I cast existing record on form I have an issue with tracking this overridden attribute. It shown like changed ({ "market_id" => [nil, 1] }) but no changes happened on it at all. I think it happens because of this desynchronization between real database and model changes and form changes.

So my point is to copy @mutations_from_database to be sure that all required trackers set or unset after model cast on form.