what migrations should I create and what relation should I use?
-
2You could solve it in multiple ways... you could use a Product Model and use Single Table Inheritance (STI) to define a Movie and Book Model that inherits from Product (then fields like genre, media, author become part of Product). Or you can create separate MovieProduct and BookProduct models, each containing all the fields they share commonly. Which you choose is up to you, each has its own pro's and con's.bo-oz– bo-oz2015-11-30 11:29:42 +00:00Commented Nov 30, 2015 at 11:29
-
@bo-oz Could you give me a link where I can find more information about the STIuser2420249– user24202492015-11-30 12:28:02 +00:00Commented Nov 30, 2015 at 12:28
-
See link by nidhimj22. But before you choose, I'd advice you to read this as well: about.futurelearn.com/blog/refactoring-rails-stibo-oz– bo-oz2015-11-30 12:52:03 +00:00Commented Nov 30, 2015 at 12:52
Add a comment
|
1 Answer
You can use Rails Single Table inheritance as your models share much of the same functionality and data fields. You will end up having something like this.
# /app/models/products/product.rb
class Product < ActiveRecord::Base
# Methods, variables and constants
end
# /app/models/products/movie.rb
class Movie < Product
# Methods, variables and constants
end
# /app/models/products/book.rb
class Book < Product
# Methods, variables and constants
end
To read more about STI refer Rails Documentation or this
