This project is archived and is in readonly mode.
joins() on has_one through generates SQL query with "IS NULL"
-
Joeri Samson
I have the same problem (also using Rails 3.0.3, but using JRuby), additionally if I make the join 1 level deeper I get an INNER JOIN
table_nameON 0.class FociSample < ActiveRecord::Base belongs_to :foci_group has_one :source_well, :through => :foci_group end class FociGroup < ActiveRecord::Base belongs_to :source_well, :foreign_key => "source_id", :class_name => "CultureWell" end class CultureWell < ActiveRecord::Base belongs_to :culture_plate endWhen trying
the generated query is:FociSample.joins(:source_well => :culture_plate)
SELECTfoci_samples.* FROMfoci_samplesINNER JOINfoci_groupsONfoci_samples.idIS NULL INNER JOINculture_wellsON 0 INNER JOINculture_platesONculture_plates.id=culture_wells.culture_plate_idAdding an additional level
results in this query:class CulturePlate < ActiveRecord::Base belongs_to :culture_batch end
FociSample.joins(:source_well => {:culture_plate => :culture_batch})
where the join condition for the extra dependency makes sense again.SELECTfoci_samples.* FROMfoci_samplesINNER JOINfoci_groupsONfoci_samples.idIS NULL INNER JOINculture_wellsON 0 INNER JOINculture_platesONculture_plates.id=culture_wells.culture_plate_idINNER JOINculture_batchesONculture_batches.id=culture_plates.culture_batch_id -
Jon Leighton
- State changed from new to duplicate
- Importance changed from to Low
Hi there,
Thanks for the bug report.
This is a duplicate of #2801 incorrect sql from has_many :through , which is fixed in master.
Jon