pretty_print

pretty_print(q) Instance Public methods

new 2

new(*args, &block) Instance Public methods Initializes new record from relation while maintaining the current scope. Expects arguments in the same format as Base.new. users = User.where(name: 'DHH') user = users.new # => #<User id: nil, name: "DHH", created_at: nil, updated_at: nil> You can also pass a block to new with the new record as argument: user = users.new { |user| user.name = 'Oscar' } user.name # => Oscar build

many?

many?() Instance Public methods Returns true if there is more than one record.

load

load() Instance Public methods Causes the records to be loaded from the database if they have not been loaded already. You can use this if for some reason you need to explicitly load some records before actually using them. The return value is the relation itself, not the records. Post.where(published: true).load # => #<ActiveRecord::Relation>

joined_includes_values

joined_includes_values() Instance Public methods Joins that are also marked for preloading. In which case we should just eager load them. Note that this is a naive implementation because we could have strings and symbols which represent the same association, but that aren't matched by this. Also, we could have nested hashes which partially match, e.g. { a: :b } & { a: [:b, :c] }

inspect

inspect() Instance Public methods

initialize_copy

initialize_copy(other) Instance Public methods

find_or_initialize_by

find_or_initialize_by(attributes, &block) Instance Public methods Like find_or_create_by, but calls new instead of create.

find_or_create_by!

find_or_create_by!(attributes, &block) Instance Public methods Like find_or_create_by, but calls create! so an exception is raised if the created record is invalid.

find_or_create_by

find_or_create_by(attributes, &block) Instance Public methods Finds the first record with the given attributes, or creates a record with the attributes if one is not found: # Find the first user named "Penélope" or create a new one. User.find_or_create_by(first_name: 'Penélope') # => #<User id: 1, first_name: "Penélope", last_name: nil> # Find the first user named "Penélope" or create a new one. # We already have one so the existing record will be returned. User.f