小花的传承
我最近开始使用 Kohana,我知道继承目前还处于起步阶段。解决方法是在子类模型上使用 $_has_one 注释。在可能的情况下,我将“页面”作为“文章”的父级。我有类似的东西,
protected $_has_one = array('mypage'=>array('model'=>'page', 'foreign_key'=>'id'));
在我的控制器,我有一个查询数据库的操作。在此查询中,我尝试访问“文章”的父级(即“页面”)中的字段。
$n->articles=ORM::factory('article')->where('expires','=',0)
->where('articledate','<',date('y-m-d'))
->where('expirydate','>',date('y-m-d'))
->where('mypage->status','=','PUBLISHED')
->order_by('articledate','desc')
->find_all();
状态列驻留在页表中,我的查询生成了一个错误,大意是“找不到状态”,显然是因为它属于父级。
有什么想法吗?
I have recently started to use Kohana and I know inheritance is in infancy stages at the moment. The work around is using a $_has_one annotation on the child class model. In may case i have "page" as the parent of "article". I have something like,
protected $_has_one = array('mypage'=>array('model'=>'page', 'foreign_key'=>'id'));
In my controller, I have an action which queries the database. In this query I am trying to access fields from the parent of "article" which is the "page".
$n->articles=ORM::factory('article')->where('expires','=',0)
->where('articledate','<',date('y-m-d'))
->where('expirydate','>',date('y-m-d'))
->where('mypage->status','=','PUBLISHED')
->order_by('articledate','desc')
->find_all();
The status column resides in the page table and my query is generating an error to the effect of "cannot find status", clearly because it belongs to the parent.
Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以像这样使用with:
这会在两个一对一的表之间创建连接。
It may be possible to use with like this:
Which creates a join between two one to one tables.