Enforce eager loading of backreferencing to avoid wasteful SQL queries
This commit is contained in:
parent
20a627a270
commit
78b8f594af
2 changed files with 2 additions and 6 deletions
|
|
@ -1,3 +1,3 @@
|
|||
class Package < ActiveRecord::Base
|
||||
has_many :screenshots
|
||||
has_many :screenshots, :inverse_of=>:package
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue