Q:

How to create this `through`` association?

Organization and Link are associated through Node. 
Organization:
has_many :nodes
has_many :links, through: :nodes, source: :where_first_links

Node:
belongs_to :organization
has_many :where_first_links, class_name:  "Link",
                             foreign_key: "first_node_id"
has_many :where_second_links, class_name:  "Link",
                              foreign_key: "second_node_id"

Link:
belongs_to :first_node,  class_name: "Node"
belongs_to :second_node, class_name: "Node"

Question:: How can I associate Link back to Organization? I tried the line below but that does not seem to work (ArgumentError: Unknown key: :through.):
belongs_to :organization, 
           through: :first_node, 
           source: :where_first_links, 
           inverse_of: :links

A:

belongs_to association  not support through key
you should use has_one association
has_one :first_node_organization, 
        through: :first_node, 
        class_name: 'Organization', 
        source: :organization

