开发者

Getting an attribute directly from rails Class.find(:all) array of objects

开发者 https://www.devze.com 2023-02-11 13:18 出处:网络
I know that Person.find(:all) returns an array of Person objects but is there somehow I can just get \'name\' p开发者_开发知识库roperty of all people in the Person table?

I know that Person.find(:all) returns an array of Person objects but is there somehow I can just get 'name' p开发者_开发知识库roperty of all people in the Person table?

Something like

        Person.find(:all).names


Use :select to retrieve only specific attributes.

Person.all(:select => :name)

Would give you person objects that only have the name attribute initialized. Then you can map/collect that attribute to get the array of names.

0

精彩评论

暂无评论...
验证码 换一张
取 消