- 英文:
- Default scopes apply to all queries that start with this model.
- We ask our customer whether she had a preference regarding the order things should be listed in, and we jointly decided to see what happened if we displayed the products in alphabetical order. We do this by adding a default_scope call to the Product model. Default scopes apply to all queries that start with this model.
- 中文:
- 这种默认的scope方法/函数适用于所有该模型的查询。
- 道喜评论
- 看来必须承认:这句话原作者说明不够透出。
- 书上代码default_scope是一个方法/函数,这是有特殊作用的方法/函数,其作用源代码是这样说明的:http://tinyurl.com/6zdewb3
- You can define a scope that applies to all finders using ActiveRecord::Base.default_scope.(这个方法/函数可以作用/适用于所有的查询。)
- 这句话使用default scopes,这说明还有不是默认(default)的scope方法/函数,请看API说明: http://tinyurl.com/366bkjo
- 这种默认方法/函数可以在一个模型里存在多个。所以原文使用复数。请看下面代码。
- function或者method,在软件科学中,我以为,它们是一个概念。但是,就是我写自己东西,也会使用方法或者函数。必须提醒开始接触Rails框架的朋友:在Ruby语言中,对象或者类的属性本身就是方法/函数。我以为,没有必要太多抓住“概念”,而是要理解“概念”,更重要的是:自己真正明白”概念“。
- 这里的Default scopes肯定是指:default_scope 方法/函数。我以为,scopes不应该翻译为“范围限定,范围设定,作用范围”等中文含义。
- 读者是否会联想到,”默认的scope(方法/函数)就是default_scope 方法/函数“?所以利用上下文关系,翻译为“所有这类函数”或者“所有这类方法”,是否更为妥当?