Guest User

Untitled

a guest
Mar 13th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. ## TODO: There has *got* to be another way to do this. It's ridiculous.
  2. def all_by_tags some_tags
  3. query = []
  4. some_tags.each do |tag|
  5. query << 'SELECT taggings.post_id FROM tags LEFT JOIN taggings ON tags.id = taggings.tag_id WHERE tags.name = ?'
  6. end
  7.  
  8. post_ids = database.query([query.join(" UNION "), some_tags].flatten)
  9. Post.all(post_ids)
  10. end
Add Comment
Please, Sign In to add comment