Reputation: 1596
I'm trying to change a column name as a way to sort a legacy db we have. I've already found a fix here but am trying a different method.
I don't seem able to to use the AS statement. I've tried all these:
@radcheck = Radcheck.find(:all, :select => 'attribute AS attr')
And:
@radcheck = Radcheck.find_by_sql("select attribute AS attr from radcheck")
When I run the latter in the console, it seems to work ok but the output isn't correct:
irb(main):076:0* @radcheck = Radcheck.find_by_sql("select 'username, attribute AS attr' from radcheck")
Radcheck Load (22.4ms) select 'username, attribute AS attr' from radcheck
=> [#<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >, #<Radcheck >]
Is there something stupid I'm doing here?
Upvotes: 0
Views: 562
Reputation: 47638
Have you tried to access attributes of @radcheck
elements? These attributes are not printed by inspect
method (that is called by irb on the object when it tries to display it), but that doesn't mean they're not there. Try printing directly @radcheck.first.attr
for example.
Upvotes: 1