About create rules(unique or not unique) in models

Hello guys,

I have a problem about the rules in Yii’s model. For example, I have a project and issue controller+model in my application.

You need to choose a project FIRST and then you can create issue/update issue/delete issue in this SPECIFIC project.

I use the filter chain to pass a parameter called "pid" to make sure each issue has a parameter pid so the user have to choose project first, then you can access/create specific issue under specific project.

As we all know, we can use the following way to prevent the REPEAT name of the issue. That is , use “unique”. So you can’t create 2 same issues in my application.


public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			

                        array('name','unique', 'message'=>'This issue already exists.'),

			

		);

	}

These code will prevent all same issues(same name) in my app, regardless their according project name.

However, I need that people can create the same issues among different project.

For example. I have 2 projects, p1 and p2

I would like the user to create ‘issue-one’ in p1 and ‘issue-one’ in p2 and that will not be conflict because the codes above(“unique” part).

But you can’t create two ‘issue-one’ in p1. …

That is, you can create issues that have the same names in different project but not in the same project.

What should I do ???

Any ideas?

I would really appreciate if you guys can help me…

Thanks so much!!!!

You can try unique-attributes-validator or unique-multiple-columns-validate.

Is this what you want?

you can also Create your own Validation Rule…

Thanks .That solved my problem.

Thank you very much.

Thanks!