Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5077 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] (tiny) inconsistency: AR::Base#type_condition vs. JoinAssociation#association_join in handling STI inherintance column value

Reported by: info@loobmedia.com Assigned to: David
Priority: normal Milestone: 1.2
Component: ActiveRecord Version: 1.1.1
Severity: normal Keywords:
Cc: marcel@vernix.org

Description

AR::Base#type_condition uses Inflector.demodulize on class names, whereas AR::Associations::JoinDependency::JoinAssociation#association_join doesn't do this at all, causing issues when combining STI and modulized AR classes. This is true when using the :include option for example. All unit tests pass. Due to the edge-case nature of the issue (and the evidence that it clearly is an inconsistency) no additional unit tests have been added. My own implementation/specific unit test confirms that it works though.

before applying the patch (incorrect):

... LEFT OUTER JOIN folder_entries ON folder_entries.owner_id = pages.id AND folder_entries.owner_type = 'Page'AND folder_entries."type" = 'Folder::Favorite' ...

after applying the patch (correct):

... LEFT OUTER JOIN folder_entries ON folder_entries.owner_id = pages.id AND folder_entries.owner_type = 'Page'AND folder_entries."type" = 'Favorite' ...

Attachments

associations.rb.diff (0.8 kB) - added by info@loobmedia.com on 05/14/06 10:00:51.
associations_with_modules_fix.diff (1.8 kB) - added by info@loobmedia.com on 05/15/06 11:40:06.
associations_with_modules_fix.2.diff (1.4 kB) - added by info@loobmedia.com on 05/15/06 11:58:28.

Change History

05/14/06 10:00:51 changed by info@loobmedia.com

  • attachment associations.rb.diff added.

05/14/06 18:27:26 changed by marcel

  • cc set to marcel@vernix.org.

In order to obviate regressions, could you add some unit tests for this? Thanks.

05/15/06 11:39:38 changed by info@loobmedia.com

I've included a new PATCH, which includes a unit test that now passes thanks to the small fix to associations.rb. It demonstrates that effectively the :include option now works as expected, as to before, the @firm instance variable isn't preloaded as it should have been. Since any call to account.firm would load it afterall, such a scenario was a bit hard to trace without looking at the logs.

05/15/06 11:40:06 changed by info@loobmedia.com

  • attachment associations_with_modules_fix.diff added.

05/15/06 11:58:28 changed by info@loobmedia.com

  • attachment associations_with_modules_fix.2.diff added.

05/15/06 14:08:53 changed by rick

  • status changed from new to closed.
  • resolution set to fixed.

(In [4342]) Call Inflector#demodulize on the class name when eagerly including an STI model. Closes #5077 [info@loobmedia.com]