This project is archived and is in readonly mode.

#5064 ✓resolved
Will St. Clair

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

Reported by Will St. Clair | July 7th, 2010 @ 06:27 PM | in 3.x

(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


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.

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>

Referenced by