新手问题 关于 ActiveRecord 的 select 一定会返回主键的问题

a886937 · November 17, 2017 · Last by a886937 replied at November 17, 2017 · 1161 hits

各位好,请教大家一个问题。目前有 A 表,表主键为 Id,当我执行 A.select(:UserId) 时一定会返回{Id:xxxx,UserId:1230} 这样组成的数组,有什么办法可以过滤掉主键麻,而不是我再去执行一次循环,去掉他,找遍 stackoverflow 都无解。

A.pluck(:user_id)

@Garrus @teddyinfi 确实可以,多谢两位😀

a886937 closed this topic. 17 Nov 22:40
You need to Sign in before reply, if you don't have an account, please Sign up first.