How can I tell Activerecord to not load blob columns unless explicitly asked for? There are some pretty large blobs in my legacy DB that must be excluded for 'normal' Objects.
相关问题
- Views base64 encoded blob in HTML with PHP
-
undefined method `type_cast' for #
- Rails how to handle error and exceptions in model
- Is there a way to remove the id column in a subseq
- Lazily Reading a File in D
相关文章
- how to call a active record named scope with a str
- Got ActiveRecord::AssociationTypeMismatch on model
- How to determine if association changed in ActiveR
- Does rails support mysql json data type
- Routing to sub routing module without lazy loading
- Lazy Load VS infinite scrolling
- Should we disable lazy loading of Entity Framework
- Rails - Active Record: add extra select column to
A clean approach requiring NO CHANGES to the way you code else where in your app, i.e. no messing with
:select
optionsUsage is simple
fd's answer is mostly right, but ActiveRecord doesn't currently accept an array as a :select argument, so you'll need to join the desired columns into a comma-delimited string, like so:
I believe you can ask AR to load specific columns in your invocation to find:
However, this would need to be updated as you add columns, so it's not ideal. I don't think there is any way to specifically exclude one column in rails (nor in a single SQL select).
I guess you could write it like this:
Test these out before you take my word for it though. :)
I just ran into this using rail 3.
Fortunately it wasn't that difficult to solve. I set a
default_scope
that removed the particular columns I didn't want from the result. For example, in the model I had there was an xml text field that could be quite long that wasn't used in most views.You'll see from the solution that I had to map the columns to fully qualified versions so I could continue to use the model through relationships without ambiguities in attributes. Later where you do want to have the field just tack on another
.select(:data)
to have it included.