当使用关联扩展VS命名范围? [英] When to use association extensions vs named scopes?

查看:177
本文介绍了当使用关联扩展VS命名范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个粗略地看一眼,他们似乎根本就是两个不同的方法,以同一套问题,除了命名范围是可链接的,而联想的扩展都没有。

From a cursory glance, they appear to be simply two different approaches to the same set of problems, except that named scopes are chainable, while association extensions are not.

任何人都可以进一步解释,或提供一个例子,这将是更适合的关联扩展名不是一个名为范围有多大?

Can anyone explain further, or provide an example that would be more appropriate for an association extension than a named scope?

推荐答案

协会扩展为创建创建自定义的方法,更新等(不一定找到)非常有用的。

Association extensions are very useful for creating custom methods for creating, updating, etc (not necessarily finding).

由于您有机会获得proxy_owner,proxy_reflection,proxy_target,你有一个漂亮的勾手进的关系。

Because you have access to the proxy_owner, proxy_reflection, proxy_target, you have a nice hook into the relationship.

检查出的Rails的文档公会扩展部分:

Check out the Association Extension section of the Rails docs:

<一个href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html">http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

这篇关于当使用关联扩展VS命名范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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