


Locking is helpful for preventing race conditions when updating records in the database and ensuring atomic updates.Īctive Record provides two locking mechanisms:

#ELOQUENT MODEL RETURN SPECIFIED PROPERITES CODE#
save CopyĪs customer is explicitly set to be a readonly object, the above code will raise an ActiveRecord::ReadOnlyRecord exception when calling customer.save with an updated value of visits. Using the find method, you can retrieve the object corresponding to the specified primary key that matches any supplied options. Run after_find and then after_initialize callbacks, if any.Īctive Record provides several different ways of retrieving a single object.Instantiate the equivalent Ruby object of the appropriate model for every resulting row.Fire the SQL query and retrieve the corresponding results from the database.Convert the supplied options to an equivalent SQL query.The primary operation of Model.find(options) can be summarized as: Methods that find a single entity, such as find and first, return a single instance of the model. Each finder method allows you to pass arguments into it to perform certain queries on your database without writing raw SQL.įinder methods that return a collection, such as where and group, return an instance of ActiveRecord::Relation. To retrieve objects from the database, Active Record provides several finder methods. Retrieving Specific Data from Multiple TablesĬlass Supplier Retrieving Filtered Data from Multiple Tables.What is the Active Record Query Interface?.
