Search code examples
ruby-on-railsruby-on-rails-3arel

How to convert SQL to Arel?


Is there a way to convert the MATCH and AGAINST parts to Arel?

I could not find anything about it in the Arel source code.

I'm using Rails 3.

SELECT gigs.time, gigs.channel_id, gigs.song_id, gigs.id, 
  MATCH (songs.title) AGAINST (?) AS song_score,
  MATCH (artists.name) AGAINST (?) AS artist_score
  FROM songs
  INNER JOIN artists ON artists.id = songs.artist_id
  INNER JOIN gigs ON gigs.song_id = songs.id
  WHERE MATCH (artists.name) AGAINST (?) OR
  MATCH (songs.title) AGAINST (?)
  HAVING (artist_score + song_score) > 0

Solution

  • AFAIK there is no Arel MATCH AGAINST implementation. My guess is because it is not pure SQL, but specific to MySQL.