最新消息: 新版网站上线了!!!

thinkPHP3.2关联模型之一对一

A表---a_goods

B表---a_goods_thumb


 

GoodsModel.class.php
<?php
namespace Home\Model;
use Think\Model\RelationModel;
class GoodsModel extends RelationModel{
    protected $tableName = 'goods';
    protected $_link = array(
        'goods_thumb'=>array(
            'mapping_type'=> self::HAS_ONE,//注意:这里跟thinkPHP3.1的区别
            'forgin_key'=> 'goods_id',
            'class_name'=>'goods_thumb',
            'mapping_name'=>'goods_thumb',
            'mapping_fields'=>'bigimg',
            'as_fields'=>'bigimg:goods_img',
            ),
        );
}
?>

$goods = D('Goods')->relation(true)->select();//执行查询
        p($goods);//打印数组

转载请注明:谷谷点程序 » thinkPHP3.2关联模型之一对一