Yii. Object of class AppCompany could not be converted to string on validation

533 Views Asked by At

I've been trying to implement this for my AR relations: http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/ And doing:

public function actionCreate()
{
    $application = new Application;
    $company = new AppCompany;

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Application'], $_POST['AppCompany']))
    {
        $application->attributes=$_POST['Application'];
        $company->attributes=$_POST['AppCompany'];

        $valid=$application->validate();
        $valid=$company->validate() && $valid;

        if($valid)  
        {  
            if($application->save(false))
            {
                $company->applicant_id = $application->id;
                $company->save(false);
                $this->redirect(array('view','id'=>$application->id));
            }

        }

    }

    $this->render('create',array(
        'application'=>$application,
        'company'=>$company,
    ));
}

Then, when I try to create a new application and enter all valid data - this data successfully saves into both tables. But if I leave some fields empty (while they are required), then I have this error: Object of class AppCompany could not be converted to string on validation.

Please, could you kindly figure me on my mistake?

0

There are 0 best solutions below