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?
Have you tried to access attributes of
@radcheckelements? These attributes are not printed byinspectmethod (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.attrfor example.