Enforce eager loading of backreferencing to avoid wasteful SQL queries

This commit is contained in:
Christoph Haas 2013-08-07 21:37:14 +02:00
parent 20a627a270
commit 78b8f594af
2 changed files with 2 additions and 6 deletions

View file

@ -1,3 +1,3 @@
class Package < ActiveRecord::Base
has_many :screenshots
has_many :screenshots, :inverse_of=>:package
end

View file

@ -1,10 +1,6 @@
class Screenshot < ActiveRecord::Base
belongs_to :package
belongs_to :package, :inverse_of=>:screenshots
# Return the URL to this screenshot.
# size: 'small' (thumbnail) or 'large' (full-size)
# (If possible serve the screenshots statically from the web server.)
#attr_accessor :image_url
def image_url(size)
# TODO: Prevents proper eager loading somehow...
"/screenshots/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png"