create_with

create_with(value) Instance Public methods Sets attributes to be used when creating new records from a relation object. users = User.where(name: 'Oscar') users.new.name # => 'Oscar' users = users.create_with(name: 'DHH') users.new.name # => 'DHH' You can pass nil to create_with to reset attributes: users = users.create_with(nil) users.new.name # => 'Oscar'

bind

bind(value) Instance Public methods

not

not(opts, *rest) Instance Public methods Returns a new relation expressing WHERE + NOT condition according to the conditions in the arguments. not accepts conditions as a string, array, or hash. See where for more details on each format. User.where.not("name = 'Jon'") # SELECT * FROM users WHERE NOT (name = 'Jon') User.where.not(["name = ?", "Jon"]) # SELECT * FROM users WHERE NOT (name = 'Jon') User.where.not(name: "Jon") # SELECT * FROM users WHERE name != 'Jon' User.where.not

new

new(scope) Class Public methods

find_by_sql

find_by_sql(sql, binds = []) Instance Public methods Executes a custom SQL query against your database and returns all the results. The results will be returned as an array with columns requested encapsulated as attributes of the model you call this method from. If you call Product.find_by_sql then the results will be returned in a Product object with the attributes you specified in the SQL query. If you call a complicated SQL query which spans multiple tables the columns specified

count_by_sql

count_by_sql(sql) Instance Public methods Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part. The use of this method should be restricted to complicated SQL queries that can't be executed using the ActiveRecord::Calculations class methods. Look into those before using this. Parameters sql - An SQL statement which should return a count query from the database, see the example below. Product.count_by_sql âSELECT COUNT(*) FROM sales s, cust

call

call(env) Instance Public methods

new

new(app) Class Public methods

uncached

uncached(&block) Instance Public methods Disable the query cache within the block if Active Record is configured. If it's not, it will execute the given block.

cache

cache(&block) Instance Public methods Enable the query cache within the block if Active Record is configured. If it's not, it will execute the given block.