0

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?

Wooble
  • 87,717
  • 12
  • 108
  • 131
Decd
  • 65
  • 8
  • Sorry for bother you, but I've just found a mistake: – Decd Apr 16 '14 at 19:53
  • It was here: errorSummary(array($application, $company)); ?>, and I wrote it like errorSummary($application, $company); ?>. Anyways, can you please suggest a good article how can I make an update and delete functionality for these models? – Decd Apr 16 '14 at 19:56
  • use gii for generate update, delete actions – Alex Apr 16 '14 at 19:57
  • It was generated allready, but I don't know how to realize it for related tables – Decd Apr 16 '14 at 19:59
  • it's not simple question, just try it. – Alex Apr 16 '14 at 20:02

0 Answers0