Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorThijs
    • CommentTimeMar 11th 2008 edited
     

    Is there a way to (temporary) exclude associated records from validation?

    For instance:

    • when I update one Member of a Group I want to check on the presence of some fields
    • but when I update the Group's details.. I don't want 1 empty field in some Member record to initiate a rollback (which it does now)

    Just not including the Member model in the edit page for a Group isn't an option, because I need the members displayed on the page in a list.

    I'm also wondering: what is the use of the validatesAssociated function, since there seems to be called a validation on the associated models anyway? Maybe I should only use validatesAssociated if I want an error returned? (which by the way is a generic ''Modelname is invalid')

    •  
      CommentAuthorbermi
    • CommentTimeMar 13th 2008
     

    Thijs, shouldn't Member validation rules be consistent regardless where those members belong?

    Anyhow, you could use something like this on your Group model

    function save()
    {
        $LoadedMembers = $this->members;
        unset($this->members);
        $result = parent::save();
        $this->members = $LoadedMembers;
        return $result;
    }
    

    validatesAssociated is just for quick checking loaded associates validity.

    • CommentAuthorThijs
    • CommentTimeMar 14th 2008 edited
     

    Works like a charm!

    Thijs, shouldn't Member validation rules be consistent regardless where those members belong?

    In a perfect world.. The problem is that Members are added first (with only a check on uniqueness of their e-mail address) and their details can be added later. And those details have to be validated because other, er.. more detailed details, depend on the first batch being entered.

    But at the same time the Group details must be up-datable.

    Anyway, hacking save() is not pretty, but the alternative would be to add custom validation methods (and use save(0) ) in several places.

    Thanks Bermi!

Add your comments
    Username Password
  • Format comments as