Reading a record includes specifying those specific data that you are interested in, you specify criteria for the active record, and the active record returns you some objects that contain data that matches the criteria.
The easiest way to retrieve data in a table is to specify the primary key, any model supports the Find () method, which supports one or more primary key values, and if only one primary key is specified, the corresponding object is returned, and if more than one primary key is specified to the Find method, the method sets the corresponding object. Note that when there is no qualifying data, a Recordnotfound exception is thrown, so if the Find method does not throw the exception, the number of objects in the returned array equals the number of IDs specified for the Find method.
An_order = Order.find (+) # Find
the ' order with ID = # Get a list of OrderID from a form, then
# sum the tot Al value
order_list = params[:order_ids]
orders = Order.find (order_list)
count = Orders.size
Typically, you use a value other than the ID in a query, and the Active record provides a set of settings to execute these queries, and we introduce find usage, from basic queries to higher-order dynamic queries.
By now we've just learned the basics of the Find method by specifying IDs to get one or a group of objects. In addition, we can use some tags such as: First,:all as the parameters of the Find method.
: First returns a record that matches the criteria: all returns all eligible records, and next we look at how the active record handles SQL.