Skip to content

Commit 15cab86

Browse files
committed
Replace Product with Book in "Creating Namespaced Models" section of docs for consistency
1 parent 7c68c52 commit 15cab86

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

guides/source/active_record_basics.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -250,71 +250,71 @@ purposes.
250250
Active Record models are placed under the `app/models` directory by default. But
251251
you may want to organize your models by placing similar models under their own
252252
folder and namespace. For example, `order.rb` and `review.rb` under
253-
`app/models/product` with `Product::Order` and `Product::Review` class names,
253+
`app/models/books` with `Book::Order` and `Book::Review` class names,
254254
respectively. You can create namespaced models with Active Record.
255255

256-
In the case where the `Product` module does not already exist, the `generate`
256+
In the case where the `Book` module does not already exist, the `generate`
257257
command will create everything like this:
258258

259259
```bash
260-
$ bin/rails generate model Product::Order
260+
$ bin/rails generate model Book::Order
261261
invoke active_record
262-
create db/migrate/20240306194227_create_product_orders.rb
263-
create app/models/product/order.rb
264-
create app/models/product.rb
262+
create db/migrate/20240306194227_create_book_orders.rb
263+
create app/models/book/order.rb
264+
create app/models/book.rb
265265
invoke test_unit
266-
create test/models/product/order_test.rb
267-
create test/fixtures/product/orders.yml
266+
create test/models/book/order_test.rb
267+
create test/fixtures/book/orders.yml
268268
```
269269

270-
If the `Product` module already exists, you will be asked to resolve
270+
If the `Book` module already exists, you will be asked to resolve
271271
the conflict:
272272

273273
```bash
274-
$ bin/rails generate model Product::Order
274+
$ bin/rails generate model Book::Order
275275
invoke active_record
276-
create db/migrate/20240305140356_create_product_orders.rb
277-
create app/models/product/order.rb
278-
conflict app/models/product.rb
279-
Overwrite /Users/bhumi/Code/rails_guides/app/models/product.rb? (enter "h" for help) [Ynaqdhm]
276+
create db/migrate/20240305140356_create_book_orders.rb
277+
create app/models/book/order.rb
278+
conflict app/models/book.rb
279+
Overwrite /Users/bhumi/Code/rails_guides/app/models/book.rb? (enter "h" for help) [Ynaqdhm]
280280
```
281281

282-
Once the namespaced model generation is successful, the `Product` and `Order`
282+
Once the namespaced model generation is successful, the `Book` and `Order`
283283
classes look like this:
284284

285285
```ruby
286-
# app/models/product.rb
287-
module Product
286+
# app/models/book.rb
287+
module Book
288288
def self.table_name_prefix
289-
"product_"
289+
"book_"
290290
end
291291
end
292292

293-
# app/models/product/order.rb
294-
class Product::Order < ApplicationRecord
293+
# app/models/book/order.rb
294+
class Book::Order < ApplicationRecord
295295
end
296296
```
297297

298298
Setting the
299299
[table_name_prefix](https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema.html#method-c-table_name_prefix-3D)
300-
in `Product` will allow `Order` model's database table to be named
301-
`product_orders`, instead of plain `orders`.
300+
in `Book` will allow `Order` model's database table to be named
301+
`book_orders`, instead of plain `orders`.
302302

303-
The other possibility is that you already have a `Product` model that you want
303+
The other possibility is that you already have a `Book` model that you want
304304
to keep in `app/models`. In that case, you can choose `n` to not overwrite
305-
`product.rb` during the `generate` command.
305+
`book.rb` during the `generate` command.
306306

307-
This will still allow for a namespaced table name for `Product::Order` class,
307+
This will still allow for a namespaced table name for `Book::Order` class,
308308
without needing the `table_name_prefix`:
309309

310310
```ruby
311-
# app/models/product.rb
312-
class Product < ApplicationRecord
311+
# app/models/book.rb
312+
class Book < ApplicationRecord
313313
# existing code
314314
end
315315

316-
Product::Order.table_name
317-
# => "product_orders"
316+
Book::Order.table_name
317+
# => "book_orders"
318318
```
319319

320320
Overriding the Naming Conventions

0 commit comments

Comments
 (0)