1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Query guide: specify what type of objects scopes return

This commit is contained in:
Ryan Bigg 2010-12-23 15:44:12 +10:00
parent 0795c3a15e
commit cef17cd705

View file

@ -723,7 +723,7 @@ Even though Active Record lets you specify conditions on the eager loaded associ
h3. Scopes
Scoping allows you to specify commonly-used ARel queries which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as +where+, +joins+ and +includes+.
Scoping allows you to specify commonly-used ARel queries which can be referenced as method calls on the association objects or models. With these scopes, you can use every method previously covered such as +where+, +joins+ and +includes+. All scope methods will return an +ActiveRecord::Relation+ object which will allow for further methods (such as other scopes) to be called on it.
To define a simple scope, we use the +scope+ method inside the class, passing the ARel query that we'd like run when this scope is called: