Rails: how not to include some db attributes in a model

My DB table has a column that can hold a very large amount of data. I don't want this data to be part of the corresponding rails object (model).

How do I tell in the model that I don't want to keep this field in memory?

This is initially due to my session being larger than 4k and rails throwing an ActionController :: Session :: CookieStore :: CookieOverflow exception.

Thanks for your help, Mikael.

0


a source to share


2 answers


You will need to explicitly specify the columns using the find option :select

. However, saving models in a session is not recommended. How about storing only the ID of the object in the session and placing the Model object itself in Rails.cache

?



+1


a source


When loading the model, you can explicitly specify the columns you want to select and skip the large columns:



MyModel.find(id, :select => 'column1, column2, column3')

      

+1


a source







All Articles