Skip to content

Commit 61073e3

Browse files
authored
Merge pull request rails#35888 from lxxxvi/documentation_change_foreign_keys_to_bigint_in_association_basics
change `t.integer` to `t.bigint` where applicable
2 parents 27c3ad0 + cdaa4ba commit 61073e3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

guides/source/association_basics.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ end
384384
The corresponding migration might look like this:
385385

386386
```ruby
387-
class CreateSuppliers < ActiveRecord::Migration[5.0]
387+
class CreateSuppliers < ActiveRecord::Migration[5.2]
388388
def change
389389
create_table :suppliers do |t|
390390
t.string :name
391391
t.timestamps
392392
end
393393

394394
create_table :accounts do |t|
395-
t.integer :supplier_id
395+
t.bigint :supplier_id
396396
t.string :account_number
397397
t.timestamps
398398
end
@@ -402,7 +402,7 @@ class CreateSuppliers < ActiveRecord::Migration[5.0]
402402
end
403403
```
404404

405-
NOTE: Using `t.integer :supplier_id` makes the foreign key naming obvious and explicit. In current versions of Rails, you can abstract away this implementation detail by using `t.references :supplier` instead.
405+
NOTE: Using `t.bigint :supplier_id` makes the foreign key naming obvious and explicit. In current versions of Rails, you can abstract away this implementation detail by using `t.references :supplier` instead.
406406

407407
### Choosing Between `has_many :through` and `has_and_belongs_to_many`
408408

@@ -466,11 +466,11 @@ Similarly, you can retrieve `@product.pictures`.
466466
If you have an instance of the `Picture` model, you can get to its parent via `@picture.imageable`. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:
467467

468468
```ruby
469-
class CreatePictures < ActiveRecord::Migration[5.0]
469+
class CreatePictures < ActiveRecord::Migration[5.2]
470470
def change
471471
create_table :pictures do |t|
472472
t.string :name
473-
t.integer :imageable_id
473+
t.bigint :imageable_id
474474
t.string :imageable_type
475475
t.timestamps
476476
end
@@ -619,11 +619,11 @@ end
619619
These need to be backed up by a migration to create the `assemblies_parts` table. This table should be created without a primary key:
620620

621621
```ruby
622-
class CreateAssembliesPartsJoinTable < ActiveRecord::Migration[5.0]
622+
class CreateAssembliesPartsJoinTable < ActiveRecord::Migration[5.2]
623623
def change
624624
create_table :assemblies_parts, id: false do |t|
625-
t.integer :assembly_id
626-
t.integer :part_id
625+
t.bigint :assembly_id
626+
t.bigint :part_id
627627
end
628628

629629
add_index :assemblies_parts, :assembly_id

0 commit comments

Comments
 (0)