I’ve got a User model, which has email attribute and company_id. There’s a company table and company_domain table which holds possible domains for company.
Email attribute is checked if it is a valid email, and if it match any domain form company_domain table.
After that validation i would like to set company_id attribute by checking which domain from company_domain it match. I do that in beforeValidate method of User model, but it returns no results no matter if i use find with createria or sqlcommand (select comapny_id from comapny_domain). When i run find code outside beforeValidate method i runs perfectly and finds company_doamin for particular email.
protected boolean beforeValidate()
{return} boolean whether validation should be executed. Defaults to true. If false is returned, the validation will stop and the model is considered invalid.
Make sure the parent implementation is invoked so that the event can be raised.