validates_serialized
validates_serialized copied to clipboard
Define `record` to let ValidateableObject access the outer model
I encountered a situation where I needed to give a validation on a serialized Hash access to the outer, "real" object - for instance, validations conditional on some state of the outer object (although there are other applications - I personally have a custom validation that has to check a complex predicate which may depend on state of the outer object).
This change defined @record as a readable member on ValidateableObject, which is the inner object passed to if: predicates. record will point to the outer AR::Base object through arbitrary levels of nesting (array in hash, hash in array etc).