Scopes
Scopes allow you to define a query in a model.
These can be called like ActiveRelation methods
These can accept parameters
Example, you could go to a model, like subject.rb and add:
scope :visible, where(:visible => true)
The symbol :visible is just that, a symbol. it could be anything, it's just a reference to how we can call this.
So it's saying, :visible will run where visible is true.
back in the console, you could run Subject.visible
it will return all records that have the value visible as true.
Scopes allow you to define a query in a model.
These can be called like ActiveRelation methods
These can accept parameters
Example, you could go to a model, like subject.rb and add:
scope :visible, where(:visible => true)
The symbol :visible is just that, a symbol. it could be anything, it's just a reference to how we can call this.
So it's saying, :visible will run where visible is true.
back in the console, you could run Subject.visible
it will return all records that have the value visible as true.
No comments:
Post a Comment