Note that there are some explanatory texts on larger screens.

plurals
  1. POhas_many :through - sql statement using NULL id
    primarykey
    data
    text
    <p>We recently upgraded our rails app from version 3.0.3 to 3.1.0. The application runs successfully for the most part as it did before with one major exception. We have a many-to-many relationship between two models, SurveyDatum and SubGroup, joined via a model called SubGroupSurveyDatum. Here is the code for each:</p> <pre><code>class SurveyDatum &lt; ActiveRecord::Base has_many :sub_group_survey_data has_many :sub_groups, :through =&gt; :sub_group_survey_data end class SubGroup &lt; ActiveRecord::Base has_many :sub_group_survey_data has_many :survey_data, :through =&gt; :sub_group_survey_data end </code></pre> <p>And as you might expect:</p> <pre><code>class SubGroupSurveyDatum &lt; ActiveRecord::Base belongs_to :survey_datum belongs_to :sub_group end </code></pre> <p>If I have a SurveyDatum object that I retrieved previously from the database (lets call it 'sd'), and I invoke the sub_groups method (sd.sub_groups), this is the resulting sql query generated by active record:</p> <pre><code>SELECT `sub_groups`.* FROM `sub_groups` INNER JOIN `sub_group_survey_data` ON `sub_groups`.`id` = `sub_group_survey_data`.`sub_group_id` WHERE `sub_group_survey_data`.`survey_datum_id` IS NULL </code></pre> <p>The "IS NULL" part is obviously where the id of my survey data object is supposed to go, however active record fails to use it. The object does indeed have an id, since as mentioned it was persisted and retrieved from the database. This problem only cropped up after we moved to rails 3.1, so I assume there's something I've not done properly in accordance with the new version, but I have no idea. Any ideas? Thank you in advance for your help!</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.
    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