关联模型 中间表始终不能插入数据

浏览:848 发布日期:2014/11/27 分类:求助交流
两个表 多对多的 关系 用一个中间表 保存 两个表的ID 按手册上写出 多对多的关系 结果 主表数据正常插入 中间表 一直没有数据 求救
class BlogModel extends RelationModel{
Protected $_link = array(
'cate' => array(
'mapping_type' => self::MANY_TO_MANY,
'class_name' => 'cate',
'mapping_name' => 'cates',
'foreign_key' => 'bid',
'relation_foreign_key' => 'cid',
'relation_table' => 'hd_blog_cate',
)
);

public function addBlog(){
//print_r($_POST);
$blog = D('Blog');
$data= array(
'title' => I('title'),
'content' => I('content'),
'cate' => array(
I('cid')
),
);

//print_r($data);

echo $blog->relation(TRUE)->add($data);

}


最后提交的数据 类似于
Array ( [title] => 关联模型 中间表始终不能插入数据 [content] => 内容1 [cate] => Array ( [0] => 2, [1] => 1 ) ) 提交的数据也没毛病 开了调试模式 看SQL 根本就没有一句提到 BLOG_CATE一点的内容
最佳答案
评论( 相关
后面还有条评论,点击查看>>