How to lazy load a long text field in ActiveRecord?

54 views
Skip to first unread message

mingm...@gmail.com

unread,
Apr 1, 2015, 11:32:16 AM4/1/15
to rubyonra...@googlegroups.com
If I define a model like this

class Article
    #It has fields: title, context(long text)
end

How can I retrieve articles without 'context' field loaded?

Thank you!

Frederick Cheung

unread,
Apr 1, 2015, 11:37:14 AM4/1/15
to rubyonra...@googlegroups.com
You can limit what is returned with select - Article.select('id, title') although there is no way that I am aware of to say 'all columns except this one' without explicitly listing them).

If you do this article.context would raise an error (MissingAttributeError if my memory is correct) - I think you'll have to reload the record if you do decide that you want to use that column for a particular instance

Fred 
Thank you!

mingm...@gmail.com

unread,
Apr 1, 2015, 11:42:30 AM4/1/15
to rubyonra...@googlegroups.com
Thank you , Fred!

在 2015年4月1日星期三 UTC+8下午11:37:14,Frederick Cheung写道:
Reply all
Reply to author
Forward
0 new messages