ruby on rails 3 - Activerecord solution to postgres-mysql problems -


i have following scopes in job model , seems there's problem sql discrepancies in statements. our dev db mysql , apparently heroku has postgres , keeps complaining file_count reason.

i plan convert these scopes class methods or @ least change sql statements active record ones db independent. possible @ , how start on one?

i'm planning keep is_active because i'm pretty sure works it's simple scope statement, with_unclassified_files_available_count needs refactor , think ar refactor idea(if think isn't idea, please tell me so, i'm open suggestions)

here's code:

scope :is_active, where(:active => true) scope :with_unclassified_files_available_count, where("audio_files.category_id null")                                               .joins(audio_files)                                               .select("jobs.*, count(*) 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 , audiofile belongs job.

.select("jobs.*, count(*) file_count") .group("jobs.id") 

no database, except mysql, accept construction. every column mention in select section not in aggregate function (like count, min, max) must in group by. have jobs.id in group by.

you have change query , mention columns in group by.

mysql has problems construction, in many cases produces strange/wrong results. mysql has implemented sql-mode only_full_group_by turn off behaviour, mysql reject queries this.

ps. don't use * in queries, nobody has idea results might be.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -