Took a stab at this bug because I was hoping to use this feature. Added comments in the code to try to explain what is wrong and what are my recommendations.
I have identified 2 problems that caused this to happen.
When #extract_default happens, #type_cast wrongly cast the default value to the stringified version of the array because @array was not set yet and the default value is not nil.
During the cast of the actual value (which is nil), @array is set but value is a String. [] is then returned.
Recommendations
Assign @array before extracting the default value. This allows the default to be casted properly.
If 1) the option array: true is set, 2) a default is provided and 3) value is nil; always default to the provided default.
Happy to hear any feedbacks and take any recommendations.
Bug issue: https://github.com/byroot/activerecord-typedstore/issues/80
Took a stab at this bug because I was hoping to use this feature. Added comments in the code to try to explain what is wrong and what are my recommendations.
I have identified 2 problems that caused this to happen.
#extract_default
happens,#type_cast
wrongly cast the default value to the stringified version of the array because@array
was not set yet and the default value is notnil
.nil
),@array
is set but value is a String.[]
is then returned.Recommendations
@array
before extracting the default value. This allows the default to be casted properly.array: true
is set, 2) a default is provided and 3) value isnil
; always default to the provided default.Happy to hear any feedbacks and take any recommendations.