Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord :include doesn't work with foreign keys

#2790

When creating a belongs_to association in an ActiveRecord model it's possible to have the model eager load the associated model. For example:

class Student < ActiveRecord::Base

belongs_to :lecturer

end

Using: Student.find(:all, :include => :lecturer) - should bring all the students and their lecturers, resulting in a query like "SELECT * from lecturers WHERE id IN (1, 2, 3)".

However, if we use a foreign key like so:

class Student < ActiveRecord::Base

belongs_to :lecturer, :foreign_key => :some_key

end

Using the above find will eager load only the lecturer for the first student. The rest will be lazy loaded.

Reported by johnny · June 11th, 2009 @ 03:04 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from :include, activerecord, foreign_key to :include, activerecord, bugmash, foreign_key

    August 2nd, 2009 @ 11:13 AM

  2. Cristi Balan
    Cristi Balan
    • Tag changed from :include, activerecord, bugmash, foreign_key to :include, activerecord, bugmash, foreign_key, patch

    not reproducible

    Added a patch with a test that proves it's working correctly.

    August 8th, 2009 @ 11:36 AM

  3. Gabe da Silveira
    Gabe da Silveira

    not reproducible for me either. this would be a major bug that people would notice quickly. Must be some local interaction you're having Johnny.

    August 9th, 2009 @ 12:09 PM

  4. Rizwan Reza
    Rizwan Reza

    not reproducible

    -1 Invalid.

    August 9th, 2009 @ 08:01 PM

  5. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from :include, activerecord, bugmash, foreign_key, patch to :include, activerecord, foreign_key, patch
    • State changed from new to invalid

    August 9th, 2009 @ 08:03 PM