I have the following scopes in my Job model and it seems there's a problem with some SQL discrepancies in my statements. Our dev db was mysql and apparently heroku has postgres and it keeps complaining about as file_count for some reason.
I plan to just convert these scopes into class methods or at least change the SQL statements into active record ones so it could be db independent. Is this possible at all and how would I start on this one?
I'm planning to keep is_active because I'm pretty sure it works as it's a simple scope statement, but with_unclassified_files_available_count needs a refactor and I think an AR refactor would be a good idea(if you think this isn't a good idea, please tell me so, I'm open to suggestions)
Here's the code:
scope :is_active, where(:active => true)
scope :with_unclassified_files_available_count, where("audio_files.category_id IS NULL")
.joins(AUDIO_FILES)
.select("jobs.*, COUNT(*) AS file_count")
.group("jobs.id")
.order("batch_identifier DESC")
scope :has_files_available, with_unclassified_files_available_count.having("count(*) > 0")
scope :available_to_work_on, is_active.has_files_available
Additional info:
Job has many audio_files and AudioFile belongs to job.