How do i create these associations so they are sortable?
I need some help figuring out how I should associate my models.
I have three models:
class Series < ApplicationRecord
has_many :modules
has_many :episodes
end
class Module < ApplicationRecord
belongs_to :series
has_many :episodes
end
class Episode < ApplicationRecord
belongs_to :modules, optional: true
belongs_to :series, optional: true
end
I need to be able to manually specify the order of the following has_many relationships:
- Module in a Series
- Episode in a Module
- Episode in a Series.
I believe I need a has_many, through:
, possibly 3 of them? One for each relationship, so
class Series < ApplicationRecord
has_many :modules, through: :module_series
has_many :episodes, through: :episode_series
end
class Module < ApplicationRecord
belongs_to :series
has_many :episodes, through: module_episode
end
Am i approaching this the correct way?