diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2017-06-02 14:54:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-02 14:54:32 -0400 |
commit | 57d5cf8cdeddcc379950db22d015b7f439dd6629 (patch) | |
tree | 4f3bb8ddc3b51b5a4a1501cb81f6fee2cffde2f6 | |
parent | 6bc14681e2dfc64296ef2ed03b0bb325e3aef476 (diff) | |
parent | 3ac5229f32433405628dbca0ec190f7df5013841 (diff) | |
download | rails-57d5cf8cdeddcc379950db22d015b7f439dd6629.tar.gz rails-57d5cf8cdeddcc379950db22d015b7f439dd6629.tar.bz2 rails-57d5cf8cdeddcc379950db22d015b7f439dd6629.zip |
Merge pull request #29135 from Nerian/document_support_for_composite_primary_keys
Document support for composite primary keys
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 16a398f631..6cf8645cab 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -188,6 +188,8 @@ module ActiveRecord # The name of the primary key, if one is to be added automatically. # Defaults to +id+. If <tt>:id</tt> is false, then this option is ignored. # + # If an array is passed, a composite primary key will created. + # # Note that Active Record models will automatically detect their # primary key. This can be avoided by using # {self.primary_key=}[rdoc-ref:AttributeMethods::PrimaryKey::ClassMethods#primary_key=] on the model @@ -241,6 +243,23 @@ module ActiveRecord # label varchar # ) # + # ====== Create a composite primary key + # + # create_table(:orders, primary_key: [:product_id, :client_id]) do |t| + # t.belongs_to :product + # t.belongs_to :client + # end + # + # generates: + # + # CREATE TABLE order ( + # product_id integer NOT NULL, + # client_id integer NOT NULL + # ); + # + # ALTER TABLE ONLY "orders" + # ADD CONSTRAINT orders_pkey PRIMARY KEY (product_id, client_id); + # # ====== Do not add a primary key column # # create_table(:categories_suppliers, id: false) do |t| |