Prev | Current Page 477 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


connection()
To return the connection currently associated with the class, use the connection method. This
method can also be used to obtain the connection in order to work directly with the database,
for example:
Account.connection.select_values("SELECT id FROM accounts WHERE created_at < " +
Time.now ??“ 1.day)
connection=(connection_specification)
This method manually sets the database connection for an Active Record class.
content_columns()
This method returns an array of column objects that Active Record considers the actual content,
or data, of the Active Record class. Therefore, this array does not include the primary ID
column, any columns ending in _id or _count, and any columns used for single table inheritance.
count_by_sql(sql_query_string)
The method returns the result of an SQL query that should only include COUNT(*) in the SELECT
part of the SQL query:
Account.count_by_sql("SELECT COUNT(*) FROM accounts")
create(attributes = nil)
The create method instantiates and immediately saves the Active Record class with the values
specified in the attributes hash, if validations permit.


Pages:
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489