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.

[PATCH] bug in #construct_quoted_owner_attributes at ActiveRecord::Associations::ThroughAssociationScope

#5064

(rails 3.0.0.beta4, naturally)

I have an Event model which belongs_to my Account model like so:

class Event < ActiveRecord::Base
  belongs_to :account

...and a Session model which has an Account through its ownership by Event, like so:

class Session < ActiveRecord::Base
  belongs_to :event
  has_one :account, :through => :event

However, on testing to see if Session knows who its account is, SQLite spits out a parse error because the ID is a naked string:

1) Error: test_knows_who_its_account_is(SessionTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: unrecognized token: "87b8": SELECT "accounts".* FROM "accounts" INNER JOIN "events" ON "accounts".id = "events".account_id WHERE (("events".id = bf486316-4230-4579-87b8-1f56080a3356)) LIMIT 1

{mkd-extraction-d81fe33bcae464ccc0b60450141c94d3}

A little bit of putsing revealed that the elsif reflection.macro == :belongs_to branch in ActiveRecord::Associations::ThroughAssociationScope#construct_quoted_owner_attributes does not return a quoted string. The attached patch quotes it, and results in my tests passing. Whether or not this is actually the right place to fix it is probably better determined by someone else.

Reported by Will St. Clair · July 7th, 2010 @ 06:27 PM

State: resolved
Milestone: 3.x
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Neeraj Singh
    Neeraj Singh
    • Milestone set to 3.x
    • Assigned user set to José Valim
    • State changed from new to open
    • Tag set to activerecord, patch, rails3
    • Importance changed from to Low

    Attached is test cases for the patch.

    July 8th, 2010 @ 01:50 PM

  2. José Valim
    José Valim

    Will, could you please provide a patch following the conventions at: http://rails.lighthouseapp.com/projects/8994/sending-patches

    Thanks!

    July 8th, 2010 @ 09:32 PM

  3. José Valim
    José Valim
    • Title changed from [PATCH] bug in ActiveRecord::Associations::ThroughAssociationScope#construct_quoted_owner_attributes to [PATCH] bug in #construct_quoted_owner_attributes at ActiveRecord::Associations::ThroughAssociationScope

    July 8th, 2010 @ 10:16 PM

  4. Will St. Clair
    Will St. Clair

    Neeraj --

    Thanks for the tests! Working on this today and pulled latest rails and now there is a conflict between the patch and your commits to rails core. Any preference on how I resolve this?

    Thanks,
    Will

    July 10th, 2010 @ 07:27 PM

  5. Will St. Clair
    Will St. Clair

    Ah, I see more clearly now; I will just rename Car in the patch to something else to avoid conflicting with your fix for 4984

    July 10th, 2010 @ 07:56 PM

  6. Will St. Clair
  7. Repository