Forum: Ruby on Rails EdgeRails with_scope and :select

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Vincent AE Scott (Guest)
on 2006-03-02 20: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

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

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?



 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.