You could use the beforeValidate() method on your model class to check
anything you want, something like:

class Site extends AppModel
{
        function beforeValidate()
        {
                if (!isset($this->data['Niches']) ||
empty($this->data['Niches']['id']))
                {
                        $this->invalidate('Niches');

                        return false;
                }

                return parent::beforeValidate();
        }
}

Something like that.

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!


-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Alexey
Enviado el: Domingo, 03 de Diciembre de 2006 02:26 p.m.
Para: Cake PHP
Asunto: HABTM and required relations

Hi all

I have Model where are Site-Niches connected with HABTM. But it's
possible to add Sites without selected Niches. How is it possible to
add "required" relations, so it will be error if Niches not selected?
Something like VALID_NOT_EMPTY for related records.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to