Skip to content
This repository
Browse code

Clarify use of :select on :belongs_to in AR Associations Guide

  • Loading branch information...
commit d83eda9b696f2e51c0c79dfd028b8b2d20160426 1 parent 40d049e
Mike Gunderloy ffmike authored
8 railties/doc/guides/html/association_basics.html
@@ -1185,6 +1185,14 @@ <h5 id="_tt_readonly_tt"><tt>:readonly</tt></h5>
1185 1185 <div class="para"><p>If you set the <tt>:readonly</tt> option to <tt>true</tt>, then the associated object will be read-only when retrieved via the association.</p></div>
1186 1186 <h5 id="_tt_select_tt"><tt>:select</tt></h5>
1187 1187 <div class="para"><p>The <tt>:select</tt> option lets you override the SQL <tt>SELECT</tt> clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.</p></div>
  1188 +<div class="admonitionblock">
  1189 +<table><tr>
  1190 +<td class="icon">
  1191 +<img src="./images/icons/tip.png" alt="Tip" />
  1192 +</td>
  1193 +<td class="content">If you set the <tt>:select</tt> option on a <tt>belongs_to</tt> association, you should also set the <tt>foreign_key</tt> option to guarantee the correct results.</td>
  1194 +</tr></table>
  1195 +</div>
1188 1196 <h5 id="_tt_validate_tt"><tt>:validate</tt></h5>
1189 1197 <div class="para"><p>If you set the <tt>:validate</tt> option to <tt>true</tt>, then associated objects will be validated whenever you save this object. By default, this is <tt>false</tt>: associated objects will not be validated when this object is saved.</p></div>
1190 1198 <h4 id="_when_are_objects_saved">4.1.3. When are Objects Saved?</h4>
2  railties/doc/guides/source/association_basics.txt
@@ -765,6 +765,8 @@ If you set the +:readonly+ option to +true+, then the associated object will be
765 765
766 766 The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.
767 767
  768 +TIP: If you set the +:select+ option on a +belongs_to+ association, you should also set the +foreign_key+ option to guarantee the correct results.
  769 +
768 770 ===== +:validate+
769 771
770 772 If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved.

0 comments on commit d83eda9

Please sign in to comment.
Something went wrong with that request. Please try again.