我用原生的php new实例化了后台模型,然后后台模型里的D方法又不能实例化关联模型了,返回错误不存在goods_relation数据表。
以上代码在后台模型里都没有问题。
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model {
public function getGoods($from=NULL, $limit=null){
$goods=D('GoodsRelation')->relation(true)->find($from);
return $goods;
}
}namespace Admin\Model;
use Think\Model\RelationModel;
class GoodsRelationModel extends RelationModel {
protected $tableName = 'goods';
protected $_link = array (
'detail'=>array(
'mapping_type'=>self::HAS_MANY,
'foreign_key'=>'gid'
)
)
} 最佳答案