title: How to create has_many associations in the intermediate model of has_many :through association in an optimal way Rails
body: <p>What I want is to have a Profile where I can create contents, each content could have many videos, many images and so on. That's why I'm thinking about videos and images as different tables. But I'd like to know if a video belongs to a specific profile or content without writing complicated queries.</p>
  
  <p>I have the following models, with has_many :through association</p>
  
  <pre><code>class Profile &lt; ApplicationRecord
    has_many :contents
    has_many :videos, through: :contents
  end
  
  class Content &lt; ApplicationRecord
    belongs_to :profile
    belongs_to :video
  end
  
  class Video &lt; ApplicationRecord
    has_many :contents
    has_many :profiles, through: :contents
  end
  </code></pre>
  
  <p>and the following migrations </p>
  
  <pre><code>create_table :contents do |t|
    t.string :name
    t.text :description
    t.references :video, foreign_key: true
    t.references :profile, foreign_key: true
  end
  
  create_table :profiles do |t|
    t.integer :profile_type
    t.references :user, foreign_key: true
  end
  
  create_table :videos do |t|
    t.string :name
    t.string :file
    t.string :link
  end
  </code></pre>
  
  <p>So far, my problem is that I can have only one Video per Content. How can I store many videos in Content (the intermediate table) keeping the has_many through association?</p>
  
  <p>Since I want to have different kinds of contents, that implies they would be extra tables and I would like to get some ideas that help me to improve this approach</p>
  
  <p>Note: I was reading this documentation, <a href="http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association" rel="nofollow noreferrer">http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association</a></p>