2012-05-03 71 views
0

主義1.2.4,5.3.3 PHP
表輪廓,流,事件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();