简体   繁体   English

BrowserCMS和Paperclip

[英]BrowserCMS and Paperclip

BrowserCMS can "delete" objects, which basically sets the :deleted attribute to true. BrowserCMS可以“删除”对象,它基本上将:deleted属性设置为true。 Paperclip runs the following code initially to get all objects of a specific class: Paperclip最初运行以下代码以获取特定类的所有对象:

Person.connection.select_values(Person.send(:construct_finder_sql, :select => 'id'))

This might return [1, 2, 3]. 这可能会返回[1,2,3]。 Even if, say, 3 has :deleted set to true. 即使比如说3有:删除设置为true。 Paperclip then uses ActiveRecord to get all of the People objects using the previous list of ids. Paperclip然后使用ActiveRecord使用以前的id列表获取所有People对象。 Unfortunately, BrowserCMS doesn't return objects that are marked as deleted, so Paperclip freaks out saying "Couldn't find Person with ID=3". 不幸的是,BrowserCMS不会返回标记为已删除的对象,因此Paperclip会说“无法找到ID = 3的人”。

I'm not sure where to go from here short of a monkey patch. 我不确定从这里到哪里去猴子补丁。 Thoughts? 思考?

So, the hacky way of resolving this (which could easily turn into a fork of paperclip) is to modify the code above to simply ready: 因此,解决这个问题的hacky方法(可以很容易地变成回形针的一个分支)就是修改上面的代码就可以了:

Person.all.collect(&:id)

or 要么

Person.connection.select_values(Person.send(
  :construct_finder_sql,
  :select => 'id',
  :conditions => { :deleted => false }
))

The first option simply forces the Paperclip to perform the query through Rails, which in effect is going through BrowserCMS, thus using its constraits (ie: not seeing any deleted records). 第一个选项只是强制Paperclip通过Rails执行查询,这实际上是通过BrowserCMS,因此使用其约束(即:没有看到任何已删除的记录)。 The second option does pretty much the same query, but leaves out the BCMS-deleted records. 第二个选项执行几乎相同的查询,但省略了BCMS删除的记录。

I believe the first option is best since it allows BCMS to control the query, so if anything changes, your monkey patch won't break. 我相信第一个选项是最好的,因为它允许BCMS控制查询,所以如果有任何变化,你的猴子补丁不会破坏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM