使用find_by_id方法在rails 3.0.1中选择特定字段

时间:2022-02-11 12:28:41

i would like to select specific field with alias names by method find_by_id , like using the following query

我想通过方法find_by_id选择具有别名的特定字段,就像使用以下查询一样

Model.find_by_id(params) # I am getting  all the table columns, 
                         # but i would like to have only some columns
                         # with alias names.

can you please help me to achieve this?

你能帮助我实现这个目标吗?

1 个解决方案

#1


1  

Model.select('column_name as alias').find_by_id(params)

Unless I am misunderstanding your question.

除非我误解了你的问题。

#1


1  

Model.select('column_name as alias').find_by_id(params)

Unless I am misunderstanding your question.

除非我误解了你的问题。