explain

explain() Instance Public methods Runs EXPLAIN on the query or queries triggered by this relation and returns the result as a string. The string is formatted imitating the ones printed by the database shell. Note that this method actually runs the queries, since the results of some are needed by the next ones when eager loading is going on. Please see further details in the Active Record Query Interface guide.

empty?

empty?() Instance Public methods Returns true if there are no records.

eager_loading?

eager_loading?() Instance Public methods Returns true if relation needs eager loading.

destroy_all

destroy_all(conditions = nil) Instance Public methods Destroys the records matching conditions by instantiating each record and calling its destroy method. Each object's callbacks are executed (including :dependent association options). Returns the collection of objects that were destroyed; each will be frozen, to reflect that no changes should be made (since they can't be persisted). Note: Instantiation, callback execution, and deletion of each record can be time consuming when yo

destroy

destroy(id) Instance Public methods Destroy an object (or multiple objects) that has the given id. The object is instantiated first, therefore all callbacks and filters are fired off before the object is deleted. This method is less efficient than ActiveRecord#delete but allows cleanup methods and other actions to be run. This essentially finds the object (or multiple objects) with the given id, creates a new object from the attributes, and then calls destroy on it. Parameters id

delete_all

delete_all(conditions = nil) Instance Public methods Deletes the records matching conditions without instantiating the records first, and hence not calling the destroy method nor invoking callbacks. This is a single SQL DELETE statement that goes straight to the database, much more efficient than destroy_all. Be careful with relations though, in particular :dependent rules defined on associations are not honored. Returns the number of rows affected. Post.delete_all("person_id = 5 A

delete

delete(id_or_array) Instance Public methods Deletes the row with a primary key matching the id argument, using a SQL DELETE statement, and returns the number of rows deleted. Active Record objects are not instantiated, so the object's callbacks are not executed, including any :dependent association options. You can delete multiple rows at once by passing an Array of ids. Note: Although it is often much faster than the alternative, #destroy, skipping callbacks might bypass business

create!

create!(*args, &block) Instance Public methods Similar to create, but calls create! on the base class. Raises an exception if a validation error occurs. Expects arguments in the same format as Base.create!.

create

create(*args, &block) Instance Public methods Tries to create a new record with the same scoped attributes defined in the relation. Returns the initialized object if validation fails. Expects arguments in the same format as Base.create. Examples users = User.where(name: 'Oscar') users.create # #<User id: 3, name: "oscar", ...> users.create(name: 'fxn') users.create # #<User id: 4, name: "fxn", ...> users.create { |user| user.name = 'tenderlove' } # #<User id: 5

build

build(*args, &block) Instance Public methods Alias for: new