视图模型如何查询多条记录?
时间:2010-04-30
来源:互联网
表a
id fname
1 HTML
2 HTML
3 PHP
4 CSS
表b
aid content
1 content1
2 content2
3 content3
4 content4
class NewsViewModel extends ViewModel
{
public $viewFields = array(
'a'=>array('id','fname'),
'b'=>array('aid','content','_on'=>'a.id = b.aid'),
);
}
$db = new NewsViewModel();
$list = $db->where('fname = HTML')->select();
dump($list);
输出
bool(false)
现在我想要 fname = HTML 的记录集
$list 要怎么写?
id fname
1 HTML
2 HTML
3 PHP
4 CSS
表b
aid content
1 content1
2 content2
3 content3
4 content4
class NewsViewModel extends ViewModel
{
public $viewFields = array(
'a'=>array('id','fname'),
'b'=>array('aid','content','_on'=>'a.id = b.aid'),
);
}
$db = new NewsViewModel();
$list = $db->where('fname = HTML')->select();
dump($list);
输出
bool(false)
现在我想要 fname = HTML 的记录集
$list 要怎么写?
作者: rocet 发布时间: 2010-04-30
class BlogViewModel extends ViewModel
{
public $viewFields = array(
'Blog'=>array('id','name','title'),
'Category'=>array('title'=>'category_name', '_on'=>'Blog.category_id=Category.id'),
'User'=>array('name'=>'username', '_on'=>'Blog.user_id=User.id'),
);
楼主的模型应该定义有问题。。。有时间可以看看手册,按手册说明重新定义一下
{
public $viewFields = array(
'Blog'=>array('id','name','title'),
'Category'=>array('title'=>'category_name', '_on'=>'Blog.category_id=Category.id'),
'User'=>array('name'=>'username', '_on'=>'Blog.user_id=User.id'),
);
楼主的模型应该定义有问题。。。有时间可以看看手册,按手册说明重新定义一下
作者: flyfishiii 发布时间: 2010-04-30
Blog. ???=Category.id
Blog. ???=User.id
user_id category_id 是Blog表的字段吗? 就像 id name 之类的?
还是Blog表如果要关联Category表就要在 ???那里blog的id字段前面加上关联的表名+下划线?
别的地方根手册上没什么不一样啊 手册上是3个表. 有重名的字段. 我上面的只有2个表.字段也不重名.
用不到'title'=>'category_name'这样的吧?
Blog. ???=User.id
user_id category_id 是Blog表的字段吗? 就像 id name 之类的?
还是Blog表如果要关联Category表就要在 ???那里blog的id字段前面加上关联的表名+下划线?
别的地方根手册上没什么不一样啊 手册上是3个表. 有重名的字段. 我上面的只有2个表.字段也不重名.
用不到'title'=>'category_name'这样的吧?
作者: rocet 发布时间: 2010-04-30
$db = new NewsViewModel();
$list = $db->where('表a.fname = HTML')->select();
dump($list);
$list = $db->where('表a.fname = HTML')->select();
dump($list);
作者: hexuan1922 发布时间: 2011-05-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28