[SOLVED] Need to have a validation relation to 'delete'

This question relates to the code in the discussion as below:

http://www.yiiframew…14.html#msg3314.

My code in the function rules() is actually like:



                        array('user', 'uniqueInForum', 'on'=>'insert'),


Obviously, I would not want to validate the parameter on 'delete' action.

On the other hand, the document says:

Quote

You may thus specify a rule with the 'on' option so that it is applied only to insertion or updating.

Then I found this is expected, but I still would not want to validate it on 'delete' action.

BTW, I am doing in the 'delete' action as below.



      if (isset($_POST['user'])) {


         $user->attributes=$_POST['user'];


         if ($user->validate() && $user->delete())


Is there any solution for this?

Do you mean the 'insert' rule is applied when you call $user->validate()? That shouldn't happen? Could you please double check it? If so, please create a ticket with a reproducible example. Thank you!

Hi Qiang,

Yes, I mean this rule for a 'insert' applies to a 'delete' as well. as I thought this may be an expected behavior according to the document. But if it is not expected, I am going to create a ticket.

Done.

http://code.google.c…s/detail?id=107

Try this:

<?php


      if (isset($_POST['user'])) {


         $user->attributes=$_POST['user'];


         if ($user->validate('delete') && $user->delete())





It might skip the insert scenario rules that way.  Not sure

Thanks Jonah,



         if ($user->validate('delete') && $user->delete())


It may work though I replaced Yii to that in SVN according to Qiang's comment saying:

Quote

This issue has been fixed in SVN. In 1.0.1, if you do not specify 'on' when calling

validate(), all validators will be invoked. This is not reasonable as shown in your

example. Thanks.

And my application is working fine.

Thanks!