How to lazy load a long text field in ActiveRecord?

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!

On Wednesday, April 1, 2015 at 4:32:16 PM UTC+1, [email protected]
wrote:

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?

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 , Fred!

在 2015年4月1日星期三 UTC+8下午11:37:14,Frederick C.写道:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs