使用した TP3.2 View Model クエリ
モデルは次のように記述されます
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
テーブル構造を投稿して見てください
テーブル構造を投稿して見てください