检索关系时是否可以添加 WHERE 子句?
从理论上讲,在获取与关系对应的对象的属性时是否可以添加 WHERE 子句?
就概念而言,假设我只想检索过去 5 天内发表的前 3 篇博客文章。我的“博客”对象有一个“帖子”属性,它被定义为关系。
更新...
由于有些人在理解我所说的关系的含义时遇到一些困难:
class Blog extends Doctrine_Record {
...
public function setUp() {
$this->hasMany("Note as Posts", array(
"local" => "blog_name",
"foreign" => "post_id",
"refClass" => "BlogPost"
));
}
}
如您所见,这是一种受教义支持的明确关系。当我使用它查询时:
$instanceOfBlog->Posts...........
我想知道当时是否可以添加额外的子句。
In doctrine, is it possible to add a WHERE clause when fetching a property of an object that corresponds to a relationship?
In terms of concept, let's say I want to retrieve only the first 3 blog posts made in the last 5 days. My "blog" object has a "posts" property which is defined as a relationship.
Update...
As some people are having some difficulties understanding what I mean by a relationship:
class Blog extends Doctrine_Record {
...
public function setUp() {
$this->hasMany("Note as Posts", array(
"local" => "blog_name",
"foreign" => "post_id",
"refClass" => "BlogPost"
));
}
}
As you can see, this is an explicit relationship as supported by doctrine. When I query using it:
$instanceOfBlog->Posts...........
I'd like to know if I can add additional clauses at that time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否明白你的意思,但如果这就是我在你的
BlogTable
课程中的想法:这就是你所追求的吗?这基于 Posts 对象中的
created_at
字段,并假设在Blog
和Posts
表之间定义了关系。然而我可能完全误解了你的问题:-)
Not sure I follow you, but if it's what I think then in your
BlogTable
class:Is that what you were after? This is based on the
created_at
field in the Posts object, and assumes a relationship is defined between theBlog
andPosts
tables.I may have misunderstood your question entirely however :-)