Arie Kusuma Atmaja wrote:
> jangan lupa untuk add_index :fieldnya, :tabelnya
eit, ralat, itu diatas terbalik, tabelnya dulu, baru fieldnya.
copy paste dari Rails API:
add_index(table_name, column_name, options = {})
Adds a new index to the table. column_name can be a single Symbol, or an Array
of
Symbols.
The index will be named after the table and the first column names, unless you
pass +:name+ as an option.
When creating an index on multiple columns, the first column is used as a name
for
the index. For example, when you specify an index on two columns [+:first+,
+:last+], the DBMS creates an index for both columns as well as an index for the
first colum +:first+. Using just the first name for this index makes sense,
because you will never have to create a singular index with this name.
Examples
add_index(:suppliers, :name)
generates
CREATE INDEX suppliers_name_index ON suppliers(name)
Creating a unique index
add_index(:accounts, [:branch_id, :party_id], :unique => true)
generates
CREATE UNIQUE INDEX accounts_branch_id_party_id_index ON accounts(branch_id,
party_id)
Creating a named index
add_index(:accounts, [:branch_id, :party_id], :unique => true, :name =>
'by_branch_party')
generates
CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)
--
Arie | http://www.linkedin.com/in/ariekeren
http://ariekusumaatmaja.wordpress.com | http://groups.yahoo.com/groups/id-ruby
Never say RTFM. Turn the trolls into committers (Audrey Tang, conisli-ofun.pdf)