0

I have table like this enter image description here

what migrations should I create and what relation should I use?

3
  • 2
    You 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. Commented Nov 30, 2015 at 11:29
  • @bo-oz Could you give me a link where I can find more information about the STI Commented 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-sti Commented Nov 30, 2015 at 12:52

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.