Forum: Ruby on Rails EdgeRails with_scope and :select

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7f30149100d05b8869b0ca351ef9e756?d=identicon&s=25 Vincent AE Scott (Guest)
on 2006-03-02 19:39
(Received via mailing list)
>From what i can gather the with_scope feature doesn't allow you to
specify which columns get selected.  It appears to default to "*".  So
if i specify something like:

Question.with_scope( :find => {
	:from => "questions q, answers a",
	:conditions => "q.owner = a.owner AND a.owner=1"
}) do
...
end

I'll generate SQL like:
 SELECT * FROM questions q, answers a WHERE (q.owner=a.owner AND
a.owner=1)

which might be fine if the column names in both questions and answers
were unique.

Would adding to active_record/base.rb the facility to specify what gets
selected make sense?

for example the following passed to with_scope:

:find => {
	:select => "DISTINCT q.*",
	:from => "questions q, answers a",
	:conditions => "q.owner = a.owner AND a.owner=1"
}

Could generate the following:

 SELECT DISTINCT q.* FROM questions q, answers a WHERE (q.owner=a.owner
AND a.owner=1)


I'm probably missing something here about how AR goes about doing
<clever stuff goes here> which this would right royally brake.  But if
I'm not, does it make sense?

-vince

--
keys:  http://codex.net/gpg.asc

 Democracy is a device that insures we shall be governed no better than
we deserve.
 -- George Bernard Shaw
This topic is locked and can not be replied to.