Предполагая следующие отношения между моделями из вашего изображения.
class Competition < ApplicationRecord
has_many :categories
has_many :informations
has_many :category_informations, through: :categories
end
class Category < ApplicationRecord
belongs_to :competetion
has_many :category_informations
has_many :information, through: :category_informations
end
class CategoryInformation
belongs_to :catagory
belongs_to :information
end
class Information < ApplicationRecord
belongs_to :competetion
has_many :category_informations
has_many :catagory, through: :category_information
end
Модель может связываться с one_to_many_to_many, используя: сквозную опцию
Объясняет связь, используемую для установки соединения «многие ко многим» с другой моделью.
вы можете получить category_informations от конкурса, как
Competition.first.category_informations
Это все для дела! Довольно хорошо, правда?
И вы тоже можете получить информацию из категории
Category.first.informations
На самом деле неправильной схемы не существует, просто существует неправильное описание ассоциации.
Вы можете больше использовать ассоциацию из docs в разделах 2.3 и 4.3,