开发者

Is it possible to do: user = User.find(234234) and somehow ignore some columns in the select query?

I have some columns that contain a 开发者_运维知识库large amount of data (text, etc), and sometimes I am just displaying a summary list of the rows and I don't want to fetch all that data.

Is there an option to exclude certain columns?


I don't believe you can exclude certain columns, but you can have ActiveRecord return only specific columns using the :select parameter, e.g.

@articles = Article.find( :all, :select => ‘created_at, title, summary’ )


you can find by sql query so you can fetch your required data and its easy

Post.find_by_sql("SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜