How to select only specific attributes from a model?

前端 未结 8 1690
傲寒
傲寒 2021-01-02 05:20

I want to select only specific attributes from a model(id,name).

The SQL-command can be for example:

SELECT id,name,username FROM Users

Do you know h

8条回答
  •  萌比男神i
    2021-01-02 05:43

    SQL

    SELECT id,name,username FROM Users

    RUBY

    User.select(:id, :name, :username)

    with condition, you can write like: User.select(:id, :name, :username).find_by(:age 22)

提交回复
热议问题