table_exists?

table_exists?() Class Public methods

table_name

table_name() Class Public methods

version

version() Instance Public methods

unscoped

unscoped() Instance Public methods Returns a scope for the model without the default_scope. class Post < ActiveRecord::Base def self.default_scope where published: true end end Post.all # Fires "SELECT * FROM posts WHERE published = true" Post.unscoped.all # Fires "SELECT * FROM posts" This method also accepts a block. All queries inside the block will not use the default_scope: Post.unscoped { Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10" }

default_scope

default_scope(scope = nil) Instance Protected methods Use this macro in your model to set a default scope for all operations on the model. class Article < ActiveRecord::Base default_scope { where(published: true) } end Article.all # => SELECT * FROM articles WHERE published = true The default_scope is also applied while creating/building a record. It is not applied while updating a record. Article.new.published # => true Article.create.published # => true (You c

all

all() Instance Public methods Returns an ActiveRecord::Relation scope object. posts = Post.all posts.size # Fires "select count(*) from posts" and returns the count posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects fruits = Fruit.all fruits = fruits.where(color: 'red') if options[:red_only] fruits = fruits.limit(10) if limited? You can define a scope that applies to all finders using ActiveRecord::Base.default_scope.

scope

scope(name, body, &block) Instance Public methods Adds a class method for retrieving and querying objects. A scope represents a narrowing of a database query, such as where(color: :red).select('shirts.*').includes(:washing_instructions). class Shirt < ActiveRecord::Base scope :red, -> { where(color: 'red') } scope :dry_clean_only, -> { joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true) } end The above calls to scope define class me

initialize_internals_callback

initialize_internals_callback() Instance Public methods

populate_with_current_scope_attributes

populate_with_current_scope_attributes() Instance Public methods

serializable_hash

serializable_hash(options = nil) Instance Public methods