我正在尝试执行以下操作,该数组包含一些应保存到时间线表中的数据,其余数据应保存到日历表中。但是,当时间线正确更新时,只有默认值或空数据会保存到日历中,calendar_id 字段设置为 0。
/控制器.php
$model = \Timeline\Model_Timeline::forge();
$model->calendar = \Timeline\Model_Calendar::forge();
$model->set($item);
$model->save();
/model/timeline.php
namespace Timeline;
class Model_Timeline extends \Orm\Model
{
protected static $_properties = array(
'id',
'user_id' => array(
'data_type' => 'int',
'form' => array('type' => false),
),
'calendar_id' => array(
'data_type' => 'int',
'form' => array('type' => false),
'default' => '0'
),
'created_at' => array(
'data_type' => 'int',
'form' => array('type' => false),
'default' => '0'
),
'updated_at' => array(
'data_type' => 'int',
'form' => array('type' => false),
'default' => '0'
)
);
protected static $_has_one = array(
'calendar' => array(
'key_from' => 'calendar_id',
'model_to' => 'Timeline\\Model_Calendar',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => true,
)
);
/model/calendar.php
namespace Timeline;
class Model_Calendar extends \Orm\Model
{
protected static $_properties = array(
'id',
'start',
'end',
'recurrenceRule',
'recurrenceException',
'isAllDay',
'created_at',
'updated_at'
);
protected static $_belongs_to = array(
'calendar' => array(
'key_from' => 'id',
'model_to' => 'Timeline\\Model_Timeline',
'key_to' => 'calendar_id',
'cascade_save' => true,
'cascade_delete' => true,
)
);
}