Actually, because Rails creator works with MySQL, which still isn't a full-featured SQL DBMS. In 2004 it didn't support custom types and triggers, so ActiveRecord reflects these deficiencies.<br /><br/>

15.
The Four Ways of Find
Find by id: This can either be a speciﬁc id (1), a list of ids (1, 5,
6), or an array of ids ([5, 6, 10]).
Find ﬁrst: This will return the ﬁrst record matched by the
options used.
Find all: This will return all the records matched by the options
used.
Indirectly: The ﬁnd method is used for AR lookups via
associations.

20.
Group By
:group - An attribute name by which the result
should be grouped. Uses the GROUP BY SQL-clause.
Student.ﬁnd(:all, :group => ‘graduating_class’)
SQL Executed:
SELECT * FROM users GROUP BY graduating_class;

21.
Limit & Offset
:limit - An integer determining the limit on the
number of rows that should be returned.
:offset- An integer determining the offset from
where the rows should be fetched. So at 5, it would
skip the ﬁrst 4 rows.
Student.ﬁnd(:all, :limit => 10, :offset => 0)
SQL Executed:
SELECT * FROM users LIMIT 0, 10;

25.
Associations
One to One
has_one & belongs_to
Many to One
has_many & belongs_to
Many to Many
has_and_belongs_to_many
has_many :through

26.
One to One
Use has_one in the base, and belongs_to in the
associated model.
class Employee < ActiveRecord::Base
has_one :ofﬁce
end
class Ofﬁce < ActiveRecord::Base
belongs_to :employee # foreign key - employee_id
end

48.
Validations
• Keeping Data Clean
• In object validation of ﬁelds, calculated
validations
• Instead of key constraints
• The database is for storage, the model is for
the business logic
• Kinds of validations, custom validations, etc...

49.
But Wait?
• Aren’t format, presence, relationship
validations supposed to be the database’s
job?
• Traditionally, yes.
• ActiveRecord does constraints in the
model, not the database

50.
But Why?
• Validations Constraints are Business Logic
• Business logic should be in the model
• It makes things easy
• End users can get useful error messages
• Makes the postback pattern work well

51.
Data Integrity?
• It’s still possible to do constraints in the db
• But it’s not as necessary
• Validations are constraints which make
sense in terms of functionality of the app
• The rails ways is to just use validations
• Most DBA’s insist on foreign_key
constraints