:from
Whereas the :joins option will let you specify extra tables to join to in the FROM clause, the
:from option allows you to specify the entire contents of the FROM clause of the SQL statement.
For example, given the same visits table mentioned in the :joins example, we can reverse
the query to stem from visits:
Account.find :all,
:from => "visits LEFT JOIN accounts ON visits.account=accounts.id"
And the following SQL query will result:
SELECT * FROM visits LEFT JOIN accounts ON visits.account=accounts.id
:limit and :offset
The :limit and :offset options both take an integer and correspond directly with the LIMIT
and OFFSET clauses in SQL. For example, the following statement:
Account.find :all, :limit => 10, :offset => 20
CHAPTER 2 ?– ACTIVE RECORD AND SQL 32
will find you the twenty-first to thirtieth people in the people database, using the following
SQL query:
SELECT * FROM accounts LIMIT 10 OFFSET 20
:readonly
As previously mentioned, when a query returns data columns that don??™t correspond to
columns in a table, for example, manually added joins using the :joins option or grouped
columns using :select and :group, Active Record will mark the each record returned as read
only, as it won??™t know what to do with those columns.
Pages:
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114