2012-05-03 4 views
0

教義1.2.4、PHP 5.3.3
テーブルプロフィール、ストリーム、イベントFK関係に関する問題。教義

FK:イベント - >プロファイル多対一
FK:イベント - 多対一

>ストリーム

ストリーム

$this->hasMany('modelEvent as Events', array(
      'local' => 'id', 
      'foreign' => 'stream_id' 
)); 

プロフィール

$this->hasMany('modelEvent as Events', array(
      'local' => 'id', 
      'foreign' => 'profile_id' 
)); 

イベント

$this->hasOne('modelProfile', array(
       'local' => 'profile_id', 
       'foreign' => 'id' 
)); 

$this->hasOne('modelStream', array(
       'local' => 'stream_id', 
       'foreign' => 'id' 
)); 

関係は、仕事を:(いけない

<?php 
    $event = new modelEvent(); 
    $event -> merge ($data_event); 
    $event -> modelProfile -> merge($data_profile); 
    $event -> modelStream -> merge($data_stream); 
    $event -> save(); 
?> 

答えて

0

あなたが適切にモデルに関係のデータを追加するsetRelation()メソッドを使用する必要があります。例については

$profile = new modelProfile(); 
$profile->fromArray($arrayOfData); //you can optionally populate the new model with an array of values. Values with keys that don't exist in the model will be ignored. 

$event = new modelEvent(); 
$event->setRelation('modelProfile', $profile); 
$event->save();