TP3.2.3(thinkphp3.2.3) 关联模型之---非主键关联(已亲测可用)、TP5,暂无时间测试,如果人兄有测试结果,烦请 发邮件给我一下,我好做一下更改。以方便遇到同样问题的朋友、
我的应用场景是:有一个表(风格:style表---字段:1,id 2,title),另一个表(安例:anli:字段:style 存储 风格表中的 title 的内容,这里非 id,也非主键)
<?php
namespace Wap\Model;
use Think\Model\RelationModel;
class StyleModel extends RelationModel{
protected $_link = array(
//风格对应anli
'anlis'=>array(
'mapping_type' => self::HAS_ONE,
'class_name' => 'Anli',
'mapping_key' =>'title',// style 表字段。
'foreign_key' =>'style', // anli(表),即关联模型对应表中的字段名。
'mapping_order' => 'id ASC',
'mapping_fields' => 'id,pic_m_l',
),
);
}
希望对你有帮助。
申明:本文所道之处,由本人(Lck,Ckli)亲测可用。