Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorThijs
     

    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
     

    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
     

    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!