Ruby on Rails Wednesday, April 1, 2015

Thank you , Fred!

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


On Wednesday, April 1, 2015 at 4:32:16 PM UTC+1, mingm...@gmail.com 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!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/780b6344-4597-409d-a349-5bc0f7f60517%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment