Prev | Current Page 521 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


APPENDIX ?–  ACTIVE RECORD METHODS IN DETAIL 241
Lastly, if you wish the create a UNIQUE index, use the :unique option:
add_index(:accounts, [:first_name, :last_name], :unique => true)
The SQL generated for this example would be CREATE UNIQUE INDEX accounts_first_
name_last_name_index ON accounts(first_name, last_name).
add_order_by_for_association_limiting!(sql, options)
With this method, you can modify the given SQL statement by adding the clause specified in
options[:order] to it. The PostgreSQL connection adapter overrides this method because of
its stricter standards compliance.
sql = "SELECT last_name FROM accounts"
add_order_by_for_association_limiting!(sql, :order => "last_name")
sql #=> "SELECT last_name FROM accounts ORDER BY last_name"
change_column(table_name, column_name, type, options = {})
The change_column method changes the specified column definition to match those specified
in options. See TableDefinition#column for details on what options you can use.
This method raises a NotEmplementedError by default and must be implemented by the
specific database connection adapters.


Pages:
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533