开发者

BrowserCMS and Paperclip

开发者 https://www.devze.com 2023-01-12 18:26 出处:网络
BrowserCMS can \"delete\" objects, which basically sets the :deleted attribute to true. Paperclip runs the following code initially to get a开发者_JS百科ll objects of a specific class:

BrowserCMS can "delete" objects, which basically sets the :deleted attribute to true. Paperclip runs the following code initially to get a开发者_JS百科ll objects of a specific class:

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

This might return [1, 2, 3]. Even if, say, 3 has :deleted set to true. Paperclip then uses ActiveRecord to get all of the People objects using the previous list of ids. Unfortunately, BrowserCMS doesn't return objects that are marked as deleted, so Paperclip freaks out saying "Couldn't find Person with 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:

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 (i.e.: not seeing any deleted records). The second option does pretty much the same query, but leaves out the BCMS-deleted records.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消