用的TP3.2 视图模型 查询
模型里是这样写的
PicViewModel.class.php
<?phpnamespace Home\Model;use Think\Model\ViewModel;class PicViewModel extends ViewModel{ public $viewFields =array( 'Picture'=> array('picTitle','picToken','picCategroy','picAuthor','picPostTime','_as'=>'Picture'), 'PictureAttachment' =>array('pictureid','pictureurl','creattime','_on'=>'Picture.picToken = PictureAttachment.pictureid','_as'=>'PictureAttachment'), );}
public function Pic(){ $PicModel =D('PicView'); $s1= $PicModel->field('picTitle,picCategroy,picAuthor,picPostTime,pictureurl')->order('picPostTime desc')->select(); dump($PicModel->getLastSql()); dump($s1); }
SELECT Picture.picTitle AS picTitle,Picture.picCategroy AS picCategroy,Picture.picAuthor AS picAuthor,Picture.picPostTime AS picPostTime,PictureAttachment.pictureurl AS pictureurl FROM xxx_picture Picture JOIN xxx_picture_attachment PictureAttachment ON Picture.picToken = PictureAttachment.pictureid ORDER BY Picture.picPostTime desc
贴出表结构看看
贴出表结构看看