with_scope clobbers result attributes when :joins key is specified
Reported by duncanbeevers | April 24th, 2008 @ 07:59 PM | in 2.1.1
Using with_scope with a :joins option does not narrow returned fields to those on the primary model resulting in join table attributes being added to the primary model.
Comments and changes to this ticket
-
duncanbeevers April 24th, 2008 @ 10:46 PM
Attached change to ActiveRecord::Base that gives precedence to last-specified select and provides table-name scoping to selects where joins are involved in the scoping, but not in the final set of find options.
-
duncanbeevers April 25th, 2008 @ 06:27 PM
- → Title changed from named_scope should support joins to with_scope clobbers result attributes when :joins key is specified
Attached test showing with_scope injecting false attributes when :joins key is used in scope.
-
Pratik May 13th, 2008 @ 01:55 PM
- → State changed from new to incomplete
Could you please upload a single patch ? I'm a little confused with 3 uploded patches. Also, it's good idea to use git-format-patch to create the diff file, so that you get the credit in commit message. http://rails.lighthouseapp.com/p... has a decent explanation.
I'll reopen the ticket after you upload a new patch.
Thanks !
-

Mark June 21st, 2008 @ 12:47 PM
I encountered this bug too.
I have combined the patches into one file and run the tests.
They expose the bug well so I can +1 this patch.
-
Jeremy Kemper June 22nd, 2008 @ 11:55 PM
- → Milestone changed from to 2.1.1
- → State changed from incomplete to open
- → Assigned user changed from to Jeremy Kemper
-

Repository June 23rd, 2008 @ 03:22 AM
- → State changed from open to resolved
(from [3558a50a1cb31dd207cc1932aaee5025a7dc7c1b]) Fix column collision with named_scope and :joins. [#46 state:resolved]
-

Repository June 23rd, 2008 @ 03:22 AM
(from [0fd3e4cd2b2b1b31304a922dc65284d5363f78b6]) Fix column collision with named_scope and :joins. [#46 state:resolved]
-
duncanbeevers June 23rd, 2008 @ 07:06 PM
Argh! I've helped make construct_finder_sql that little bit uglier!
-

David Stevenson July 11th, 2008 @ 05:11 PM
- → Tag changed from to activerecord joins named_scope patch
This seems like it's a problem with scoping and joins in general - couldn't this be caused by any scoped join?
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/rails/rails
Check out the development master (Edge Rails):
git clone git://github.com/rails/rails.git
Creating or reviewing a patch
See the contributor guide.
Creating a feature request
Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too"..
