加载的Blob列停止的ActiveRecord加载、Blob、ActiveRecord

由网友(仙女味的泡芙)分享简介:我怎么能告诉ActiveRecord的不加载BLOB列,除非明确要求?还有一些pretty的大水滴在我的旧的数据库,必须排除正常的对象。How can I tell Activerecord to not load blob columns unless explicitly asked for? There are...

我怎么能告诉ActiveRecord的不加载BLOB列,除非明确要求?还有一些pretty的大水滴在我的旧的数据库,必须排除正常的对象。

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.

推荐答案

我只是碰到了这个使用轨道3。

I just ran into this using rail 3.

幸运的是它并不难解决。我设置了 default_scope 的删除特定的列我没有从结果想。例如,在模型我有可能是相当长的,这不是在大多数视图使用一个XML文本字段

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.

default_scope select((column_names - ['data']).map { |column_name| "`#{table_name}`.`#{column_name}`"})

您会看到,我已映射列完全合格的版本,这样我就可以继续使用通过关系模型,而不会在属性含糊不清的解决方案。后来在那里你想有外地刚钉在另一个。选择(:数据)。将它列入

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.

阅读全文

相关推荐

最新文章