Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby On Rails multiple composite primary keys question
    primarykey
    data
    text
    <p>I am a new guy in Ruby, and I have tables with these primary keys:</p> <ol> <li><strong>transaction_types:</strong> <ul> <li>transaction_type</li> </ul></li> <li><strong>transaction_headers:</strong> <ul> <li>transaction_type</li> <li>transaction_year</li> <li>transaction_id</li> </ul></li> <li><strong>transaction_details:</strong> <ul> <li>transaction_type</li> <li>transaction_year</li> <li>transaction_id</li> <li>city_id</li> <li>ticker_id</li> </ul></li> <li><strong>tickers:</strong> <ul> <li>city_id</li> <li>ticker_id</li> </ul></li> </ol> <p>Of course, those models have other non primary keys such as customer_id, connection_id or date, or user_id, etc, but those are not important for relationships, as those are merely data or I don't have any problem with those.</p> <p>These are my models:</p> <pre><code>#models class transaction_type &lt; ActiveRecord::Base has_many :transaction_headers, :foreign_key=&gt;'transaction_type' has_many :transaction_details, :foreign_key=&gt;'transaction_type' has_many :tickers, :through=&gt;:transaction_details end class transaction_header &lt; ActiveRecord::Base belongs_to: transaction_types, :foreign_key=&gt;'transaction_type' has_many :transaction_details has_many :tickers, :through=&gt;:transaction_details end class transaction_detail &lt; ActiveRecord::Base belongs_to: transaction_headers has_many :tickers end class ticker &lt; ActiveRecord::Base end </code></pre> <p>I need to perform a relationship to each correspond primary keys.. It was easy for <strong>transaction_type</strong> to <strong>transaction_detail</strong> and <strong>transaction_header</strong>, but how do I create an association between <strong>transaction_header</strong> and <strong>transaction_detail</strong>, and also between <strong>transaction_detail</strong> and <strong>ticker</strong>? How to create the :through keys for <strong>tickers</strong> relationships?</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload