Hi,
I have a bit of an issue that I've been pondering the last few days relating to my ActiveRecord validations. I basically want certain fields to be compulsory, only when other fields have already been defined and contain certain values.
For example my app will be used to store information about computer equipment used in an ongoing project. So each item will have a class that will define what it is and different fields will be required according to which class is set. So if the class is a server I will want to make fields like processor speed, RAM, etc compulsory. If the class is a server rack I will want to make fields like building location compulsory etc etc. The conditions wont all be based around the device class field, which I think prevents the use of scenarios (I would need a combination scenario for every combination of fields that affect what is compulsory - which in turn would cause a lot of repetition and reduced flexibility)
What I would really like is something like a 'where' clause, similar to the 'on' clause, to be defined in the rules() array. Something like
array('list-of-fields', 'required', 'where'=>($this->device_class == "server"))
I can have a crack at modifying the source for this, but am loathe for 2 reasons. 1, if there is already a similar functionality that I'm just missing then it's a waste of my time. 2, I would like to stay up to date with the regular updates and modifying these files will mean I have to modify every update.
Any help greatly appreciated.
Simon