Thanks Martin, Nick, and Jason. I frankensteined something that borrows
from all three of your suggestions, and it works great.
Only thing I couldn't get working is I couldn't encapsulate the list
generation into a method:
has_many :x
:select => happy_columns.join(",")
def self.happy_columns
blah
end
Resulted in undefined method errors on happy_columns (no, I didn't actually
call it happy_columns :-)
So I just inlined the happy_columns calculation. A little messy, but at least
it works. Guess I don't understand class definition and scoping the way I
ought.
Thanks again!
-glenn
Jason King wrote:
> For robustness, might I suggest adding in a `quote_column_name` wrapping:
>
> has_many :uncontrollable_things, :select =>
> happy_columns.map{|n|connection.quote_column_name(n)}.join(", ")
>
> Same "test-free-code" caveat for me :)
>
> On Sep 8, 2009, at 12:53 PM, Nick Zadrozny wrote:
>
>> I think :select is the best you've got for something like this. But
>> all hope is not lost. My first stab at such a problem would be to use
>> the columns array on the class, like so:
>>
>> class MagicWidgets < ActiveRecord::Base
>>
>> has_many :uncontrollable_things, :select => happy_columns.join(", ")
>>
>> def self.happy_columns
>> columns.collect { |col| col.name <http://col.name> } - [
>> "big_ol_blob_1", "big_ol_blob_2" ]
>> end
>>
>> end
>>
>> I haven't tested any of that beyond the columns.collect, so you may
>> need to experiment a bit, but maybe it'll help get things going in the
>> right direction for you.
>>
>> --
>> Nick Zadrozny
>>
>>
>>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---