This project is archived and is in readonly mode.

#976 ✓wontfix
Johnathan Conley

Calculated columns with eager loading

Reported by Johnathan Conley | September 5th, 2008 @ 04:27 PM | in 2.x

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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket