views:

43

answers:

1

BrowserCMS can "delete" objects, which basically sets the :deleted attribute to true. Paperclip runs the following code initially to get all 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?

A: 

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.

slant