Transforming A Virtual Attribute In Model

Hi,

I’m trying to implement a generic method to transform a value within the Model before passing it to CDBCriteria.

The attribute is a JSON format key,value. What I’d like to do is to transform it to a string of: “k1 v1, k2 v2, …”.

I do have a custom validator with name JSONPair which makes sure if the value is in JSON format and keys or values are valid.

There are many places that I could perform the transformation:

  1. Within the validator itself

  2. beforeValidate()

  3. A new custom validator which actually doesn’t validate and only does the transformation (is my preferred method since I can apply the transformation to any attribute within the Model rules)

  4. Via Setter().

The question is what is the best practice to perform any sort of transformation in a Model?

Thanks.