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.

Calculated columns with eager loading

#976

This is a copy of trac issue 8212 as posted by chewi. I have been using this patch successfully for a long time through 2.1, and would like to re-open this feature request, or solicit comments on a different approach to enable this feature.

=== from trac ===

Chapter 15.6 of the first edition of the Agile Web Development With Rails book describes a feature called calculated columns. What it doesn't mention is that these do not work when you attempt to do eager loading with the :include option. The reason for this is twofold. Firstly, the :select options is ignored, and secondly, the returned data is parsed differently.

Ticket #7147 attemtps to resolve the :select issue but it is too restrictive since it only allows you to specify existing columns. My patch simply adds the custom :select in front of the column aliases. No special checks are made. I don't see the point in doing any since this does not happen when using :select normally.

After filling the attributes of each newly instantiated object in the usual way, the row hash is checked for any columns that are not named in the t\d+_r\d+ fashion. These columns are added to the attributes hash of the new object. This only occurs for the "t0" table otherwise the calculated column would appear in all the eagerly loaded objects as well.

I have written a small test and it works. This patch works against 1.2.3 and current SVN.

Reported by Johnathan Conley · September 5th, 2008 @ 04:27 PM

State: wontfix
Milestone: 2.x
Assigned to: Frederick Cheung Frederick Cheung
Importance: none

Activity

  1. Pratik
    Pratik
    • Assigned user set to Frederick Cheung

    December 20th, 2008 @ 03:51 PM

  2. Frederick Cheung
    Frederick Cheung
    • State changed from new to wontfix

    Not convinced of the real world usefulness. I had a very similar patch over at #1060 Allow :select option with join-based include, it's been pluginised here

    December 20th, 2008 @ 10:58 PM