重用named_scope定义另一个named_scope [英] Reusing named_scope to define another named_scope

查看:297
本文介绍了重用named_scope定义另一个named_scope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题的本质在我看来

The problem essence as I see it

有一天,如果我没有记错的话,我已经看到了重用named_scope定义另一个named_scope的一个例子。像这样的东西(不记得确切的语法,但是这正是我的问题):

One day, if I'm not mistaken, I have seen an example of reusing a named_scope to define another named_scope. Something like this (can't remember the exact syntax, but that's exactly my question):

named_scope :billable, :conditions => ...
named_scope :billable_by_tom, :conditions => {
    :billable => true, 
    :user => User.find_by_name('Tom')
}

现在的问题是:什么是确切的语法,如果可能的话呢?我不能把它找回来,而谷歌是没有帮助的。

The question is: what is the exact syntax, if it's possible at all? I can't find it back, and Google was of no help either.

的几点说明

Some explanations

为什么我真正想要的,是我用Searchlogic定义复杂的搜索,这可能会导致一个前pression是这样的:

Why I actually want it, is that I'm using Searchlogic to define a complex search, which can result in an expression like this:

Card.user_group_managers_salary_greater_than(100)

但为时已久放无处不在。因为,据我所知,Searchlogic简单的定义上飞named_scopes,我想在这样的卡类设定named_scope:

But it's too long to be put everywhere. Because, as far as I know, Searchlogic simply defines named_scopes on the fly, I would like to set a named_scope on the Card class like this:

named_scope from_big_guys, { user_group_managers_salary_greater_than(100) }

- 这是我会用那么长时间Searchlogic方法我named_scope内。但是,再一次,会是什么语法?不能看着办吧。

- this is where I would use that long Searchlogic method inside my named_scope. But, again, what would be the syntax? Can't figure it out.

恢复

Resume

那么,是named_scope嵌套(和我做的没有的意思是链接)实际上可能吗?

So, is named_scope nesting (and I do not mean chaining) actually possible?

推荐答案

请参阅本<一个href="http://stackoverflow.com/questions/29011/is-there-a-way-to-combine-named-scopes-into-a-new-named-scope">question募集时间前在这里左右。 有一个补丁在灯塔实现你的要求。

Refer to this question raised time ago here at SO. There is a patch at lighthouse to achieve your requirement.

这篇关于重用named_scope定义另一个named_scope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆