Model Rules Scenario Problem

I have model named ‘Media’ and it has the following rules for required fields:




array('name, short_name, file_size, file_type', 'required'),



I am using this model for three different controllers:

  • Audio

  • Video

  • Document

to create new Audio and Video the above required fields are working fine but when in creating new Document I want the following list of required fields:




array('name, short_name, file_size', 'required'),



which is different from the above one, so for this i have added a scenario for this case like:




array('name, short_name, file_size', 'required', 'on' => 'document'),



So, the problem is when i click save on creating new document i get the combination of both required fields in error summary section.

you can try to change your first rule to :


array('name, short_name, file_size, file_type', 'required', 'except'=>'document'),

Tried the above, but the following rule applied:




array('name, short_name, file_size, file_type', 'required'),



but i want the following rule to be applied:




array('name, short_name, file_size', 'required'),



Thanks, this worked… :) before i made some mistake in changing the code…

The except parameter works fine with Yii version 1.1.11 but this paramter doest not work with version 1.1.10, so I am still facing the same problem as mentioned in the above post.

I tried to add scenario for each controller (Audio, Video and Document) like the following:




array('name, short_name, file_size, file_type', 'required', 'on' => 'audio,video'),

array('name, short_name, file_size', 'required', 'on' => 'document'),



which solves my problem, but is there any better solution for this???

If anyone has any idea, then please let me know.

Thanks