13
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails ActiveRecordでAS句を使う方法

Posted at

以下のような形でas句の利用が可能。

result=TestTable.select("dataA as data,id")

result.dataでdataAが取得可能。

例えば、
dataB,dataAというカラムがあって似たような処理を後続で行いたい場合は、

AS句を使ってSQLを実行しておけば、同じ方法で(ex. result.data)取得結果にアクセス可能なので、

リファクタリングに使えるかも。

ActiveRecord AS句で検索しても何も出てこなかったのでメモ。

13
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?