title: How to fetch Paperclip photo urls in a SQL Query - Rails 3.1, Paperclip
body: <p>I am trying to write an API for an app using rails as the backend, which shows meal listing. Each meal item shows a name and photo. For the API, I am trying to return a JSON array, which contains all photo urls associated with a meal model and ordered by highest ranking through a sql query. I am unsure what I am suppose to put in the SELECT statement.</p>
  
  <p>How the model looks:</p>
  
  <pre><code>Meal
    has_many :photos
    #other attributes
  end
  
  Photo
    belongs_to :meal
    # paperclip stuff
  end
  </code></pre>
  
  <p>All photos are uploaded through paperclip. The setup is based on <a href="http://www.emersonlackey.com/article/paperclip-with-rails-3" rel="nofollow">Emerson Lackey's tutorial</a>. I am using PostgreSQL as the database.</p>
  
  <p>If there is a better way please also let me know.</p>