Note that there are some explanatory texts on larger screens.

plurals
  1. PORoutinely Retrieving Column from :through Table in Rails
    primarykey
    data
    text
    <p>I have a dictionary database that works for many languages. The structure is like this:</p> <p>Table: English_words </p> <ul> <li>id </li> <li>word </li> <li>wordtype </li> <li>grammar </li> </ul> <p>Table: Spanish_words (same as for English)</p> <p>Table: French_words (same as for English)</p> <p>Table: English_Spanish </p> <ul> <li>english_id </li> <li>spanish_id </li> <li>weight_english </li> <li>weight_spanish </li> <li>use_english_if </li> <li>use_spanish_if </li> </ul> <p>The last four columns are for helping my program decide which of the many possible translations are the best suited in a particular context. My English model contains </p> <pre><code>has_many :es_words, :through =&gt; :english_spanish, :order =&gt; 'weight_english ASC' </code></pre> <p>in order to get the possible Spanish translations in order of preference. Additionally, I later need to do some more complicated filtering based on the rules in the use_.._if columns. So whenever I write "this_word.es_words" to retrieve Spanish translations for an English word, I would like my resulting objects to also contain the use_.._if columns from the joining table. I cannot imagine ever needing just the translations without those columns, so I would like to solve this on a model level rather than in the controller. What is the best way to do it? </p> <p>(The reason I don't have use_if in the Spanish_words table is that I'm translating multiple languages, and the conditions will vary depending on what language I'm translating from/to)</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