@@ -44,7 +44,7 @@ Without associations, creating and deleting books for that author would require
44
44
a tedious and manual process. Here's what that would look like:
45
45
46
46
``` ruby
47
- class CreateAuthors < ActiveRecord ::Migration [7.2 ]
47
+ class CreateAuthors < ActiveRecord ::Migration [8.0 ]
48
48
def change
49
49
create_table :authors do |t |
50
50
t.string :name
@@ -193,7 +193,7 @@ Rails will look for a class named `Authors` instead of `Author`.
193
193
The corresponding migration might look like this:
194
194
195
195
``` ruby
196
- class CreateBooks < ActiveRecord ::Migration [7.2 ]
196
+ class CreateBooks < ActiveRecord ::Migration [8.0 ]
197
197
def change
198
198
create_table :authors do |t |
199
199
t.string :name
@@ -435,7 +435,7 @@ is declared.
435
435
The corresponding migration might look like this:
436
436
437
437
``` ruby
438
- class CreateSuppliers < ActiveRecord ::Migration [7.2 ]
438
+ class CreateSuppliers < ActiveRecord ::Migration [8.0 ]
439
439
def change
440
440
create_table :suppliers do |t |
441
441
t.string :name
@@ -656,7 +656,7 @@ model is pluralized when declaring a `has_many` association.
656
656
The corresponding migration might look like this:
657
657
658
658
``` ruby
659
- class CreateAuthors < ActiveRecord ::Migration [7.2 ]
659
+ class CreateAuthors < ActiveRecord ::Migration [8.0 ]
660
660
def change
661
661
create_table :authors do |t |
662
662
t.string :name
@@ -988,7 +988,7 @@ Diagram](images/association_basics/has_many_through.png)
988
988
The corresponding migration might look like this:
989
989
990
990
``` ruby
991
- class CreateAppointments < ActiveRecord ::Migration [7.2 ]
991
+ class CreateAppointments < ActiveRecord ::Migration [8.0 ]
992
992
def change
993
993
create_table :physicians do |t |
994
994
t.string :name
@@ -1020,7 +1020,7 @@ key](active_record_composite_primary_keys.html) for the join table in the
1020
1020
` has_many :through ` relationship like below:
1021
1021
1022
1022
``` ruby
1023
- class CreateAppointments < ActiveRecord ::Migration [7.2 ]
1023
+ class CreateAppointments < ActiveRecord ::Migration [8.0 ]
1024
1024
def change
1025
1025
# ...
1026
1026
create_table :appointments , primary_key: [:physician_id , :patient_id ] do |t |
@@ -1131,7 +1131,7 @@ Diagram](images/association_basics/has_one_through.png)
1131
1131
The corresponding migration to set up these associations might look like this:
1132
1132
1133
1133
``` ruby
1134
- class CreateAccountHistories < ActiveRecord ::Migration [7.2 ]
1134
+ class CreateAccountHistories < ActiveRecord ::Migration [8.0 ]
1135
1135
def change
1136
1136
create_table :suppliers do |t |
1137
1137
t.string :name
@@ -1186,7 +1186,7 @@ manage the relationship between the associated records. The corresponding
1186
1186
migration might look like this:
1187
1187
1188
1188
``` ruby
1189
- class CreateAssembliesAndParts < ActiveRecord ::Migration [7.2 ]
1189
+ class CreateAssembliesAndParts < ActiveRecord ::Migration [8.0 ]
1190
1190
def change
1191
1191
create_table :assemblies do |t |
1192
1192
t.string :name
@@ -1471,7 +1471,7 @@ To implement these associations, you'll need to create the corresponding
1471
1471
database tables and set up the foreign key. Here's an example migration:
1472
1472
1473
1473
``` ruby
1474
- class CreateSuppliers < ActiveRecord ::Migration [7.2 ]
1474
+ class CreateSuppliers < ActiveRecord ::Migration [8.0 ]
1475
1475
def change
1476
1476
create_table :suppliers do |t |
1477
1477
t.string :name
@@ -1607,7 +1607,7 @@ foreign key column (`imageable_id`) and a type column (`imageable_type`) in the
1607
1607
model:
1608
1608
1609
1609
``` ruby
1610
- class CreatePictures < ActiveRecord ::Migration [7.2 ]
1610
+ class CreatePictures < ActiveRecord ::Migration [8.0 ]
1611
1611
def change
1612
1612
create_table :pictures do |t |
1613
1613
t.string :name
@@ -1631,7 +1631,7 @@ recommended to use `t.references` or its alias `t.belong_to` and specify
1631
1631
it automatically adds both the foreign key and type columns to the table.
1632
1632
1633
1633
``` ruby
1634
- class CreatePictures < ActiveRecord ::Migration [7.2 ]
1634
+ class CreatePictures < ActiveRecord ::Migration [8.0 ]
1635
1635
def change
1636
1636
create_table :pictures do |t |
1637
1637
t.string :name
@@ -1704,7 +1704,7 @@ To support this relationship, we need to add a `manager_id` column to the
1704
1704
manager).
1705
1705
1706
1706
``` ruby
1707
- class CreateEmployees < ActiveRecord ::Migration [7.2 ]
1707
+ class CreateEmployees < ActiveRecord ::Migration [8.0 ]
1708
1708
def change
1709
1709
create_table :employees do |t |
1710
1710
# Add a belongs_to reference to the manager, which is an employee.
@@ -2176,7 +2176,7 @@ the books table. For a brand new table, the migration might look something like
2176
2176
this:
2177
2177
2178
2178
``` ruby
2179
- class CreateBooks < ActiveRecord ::Migration [7.2 ]
2179
+ class CreateBooks < ActiveRecord ::Migration [8.0 ]
2180
2180
def change
2181
2181
create_table :books do |t |
2182
2182
t.datetime :published_at
@@ -2190,7 +2190,7 @@ end
2190
2190
Whereas for an existing table, it might look like this:
2191
2191
2192
2192
``` ruby
2193
- class AddAuthorToBooks < ActiveRecord ::Migration [7.2 ]
2193
+ class AddAuthorToBooks < ActiveRecord ::Migration [8.0 ]
2194
2194
def change
2195
2195
add_reference :books , :author
2196
2196
end
@@ -2230,7 +2230,7 @@ You can then fill out the migration and ensure that the table is created without
2230
2230
a primary key.
2231
2231
2232
2232
``` ruby
2233
- class CreateAssembliesPartsJoinTable < ActiveRecord ::Migration [7.2 ]
2233
+ class CreateAssembliesPartsJoinTable < ActiveRecord ::Migration [8.0 ]
2234
2234
def change
2235
2235
create_table :assemblies_parts , id: false do |t |
2236
2236
t.bigint :assembly_id
@@ -2251,7 +2251,7 @@ are you forgot to set `id: false` when creating your migration.
2251
2251
For simplicity, you can also use the method ` create_join_table ` :
2252
2252
2253
2253
``` ruby
2254
- class CreateAssembliesPartsJoinTable < ActiveRecord ::Migration [7.2 ]
2254
+ class CreateAssembliesPartsJoinTable < ActiveRecord ::Migration [8.0 ]
2255
2255
def change
2256
2256
create_join_table :assemblies , :parts do |t |
2257
2257
t.index :assembly_id
@@ -2271,7 +2271,7 @@ The main difference in schema implementation between creating a join table for
2271
2271
` has_many :through ` requires an ` id ` .
2272
2272
2273
2273
``` ruby
2274
- class CreateAppointments < ActiveRecord ::Migration [7.2 ]
2274
+ class CreateAppointments < ActiveRecord ::Migration [8.0 ]
2275
2275
def change
2276
2276
create_table :appointments do |t |
2277
2277
t.belongs_to :physician
0 commit comments