如何访问 Mongoid 中类方法中的作用域条目?
我有一个 RSS Feed 类,它保存 feed url、名称等,我想添加一个 posts
方法来循环 feed 中的每个帖子并返回结果。我有以下代码,但收到许多 SystemStackError: stack level too deep
错误。
class Feed
field :name
field :url
belongs_to :project
def self.posts
results = []
scoped.all.each {|f| results << RssFeed.get(f.name, f.url)}
results
end
end
我的应用程序有不同的项目,每个项目都有许多提要。因此,在我的代码中,我尝试从属于特定项目的所有 rss 提要中获取所有帖子,如下所示:
project.feeds.cached
我可以在 posts 方法中调用 scoped
,该方法将返回 Mongoid ::Criteria
但 scoped.all.each
或 scoped.entries
都返回堆栈级别太深错误。我想知道如何从 posts 类方法中访问 project.feeds 范围?
提前致谢!
I have an RSS Feed class, which holds the feed url, name, etc. and I want to add a posts
method to loop through each post in the feed and returns the results. I have the following code, but am getting many SystemStackError: stack level too deep
errors.
class Feed
field :name
field :url
belongs_to :project
def self.posts
results = []
scoped.all.each {|f| results << RssFeed.get(f.name, f.url)}
results
end
end
My application has different Projects, and each project has many feeds. So in my code I'm trying to get all posts from all rss feeds that belong to a particular project like this:
project.feeds.cached
I am able to call scoped
in my posts method which will return a Mongoid::Criteria
but scoped.all.each
or scoped.entries
both return stack level too deep errors. I was wondering how I can access the project.feeds scope from within my posts class method?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的愚蠢错误 -
cached
是一个保留字。My silly mistake -
cached
is a reserved word.