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

Ticket #1732 (closed defect: untested)

Opened 3 years ago

Last modified 10 months ago

[PATCH] finder_sql for the ActiveRecord has_and_belongs_to_many is only evaluated once

Reported by: david Assigned to: David
Priority: normal Milestone:
Component: ActiveRecord Version: 0.13.1
Severity: normal Keywords:
Cc: rtomayko@gmail.com

Description

From Solomon White:

Basically, the scenario is a many-to-many relationship implemementation of a graph, in which a node can have multiple "parent" nodes and multiple "child" nodes. The idea would be to have a navigational category structure, but be able to "clone" a category just by placing it under an additional "parent" node.

If you use finder_sql for the ActiveRecord has_and_belongs_to_many association, it appears that it's evaluated once, and then cached, so trying to walk up the hierarchy tree puts you into an infinite loop, because it's not re-evaluating the finder sql to find parents of the parent node...the parent node's .parents method returns the same set of parents as the initial node did...

Attachments

active_record_bug.diff (4.7 kB) - added by david on 07/13/05 19:10:59.
Test case for the problem
habtm_finder_sql_fix.diff (0.8 kB) - added by tyler@kianta.com on 07/15/05 23:17:08.
A fix
habtm_finder_sql_fix.2.diff (0.8 kB) - added by rtomayko@gmail.com on 11/04/05 04:51:48.
Updated version of patch (the old one failed to apply)

Change History

07/13/05 19:10:59 changed by david

  • attachment active_record_bug.diff added.

Test case for the problem

07/15/05 23:17:08 changed by tyler@kianta.com

  • attachment habtm_finder_sql_fix.diff added.

A fix

07/15/05 23:17:44 changed by anonymous

  • summary changed from finder_sql for the ActiveRecord has_and_belongs_to_many is only evaluated once to [PATCH] finder_sql for the ActiveRecord has_and_belongs_to_many is only evaluated once.

07/17/05 10:06:34 changed by david

Great stuff. Could someone be so kind as to add a patch that also adds the new test tables to the other databases?

08/04/05 00:39:05 changed by anonymous

Just a note - this behavior doesn't occur in development mode but does in production.

08/16/05 09:26:06 changed by anonymous

This happens to me in development mode too on apache with mod_fastcgi. I hope this fix gets added to the next release of rails, it is amazing I have wasted so much time because of this. Thanks david, you are a genius.

11/04/05 04:30:10 changed by anonymous

  • cc set to rtomayko@gmail.com.

11/04/05 04:51:48 changed by rtomayko@gmail.com

  • attachment habtm_finder_sql_fix.2.diff added.

Updated version of patch (the old one failed to apply)

02/24/07 22:22:35 changed by josh

  • keywords set to verified.

07/20/07 02:22:47 changed by nzkoz

  • keywords deleted.

Removing the verified keyword, to get it back follow the instructions of http://wiki.rubyonrails.org/rails/pages/PatchRequirements

10/14/07 08:49:27 changed by bitsweat

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

12/17/07 20:05:15 changed by tamersalama

ref #7576