debshots/app/models/package.rb
Christoph Haas 87f545414f Getting the project working again
Replace Twitter Bootstrap by Zurb Foundation
Used @import in SCSS instad of require_tree for proper order and use of variables like $debian_color
Moved old files out of the way (renamed them to xx*)
Welcome controller (/) works
Moved templates from ERB to SLIM format
Fixed database settings
Reduced routes to working ones
Tidied up Gemfile
Checked in experimental lab files

Tried to find a good description for this massive commit :)
2014-11-16 18:26:03 +01:00

42 lines
1.4 KiB
Ruby

class Package < ActiveRecord::Base
has_many :screenshots, :inverse_of=>:package
default_scope {
order('name ASC')
}
# Return a query of all packages that have screenshots
def self.with_screenshots
# Query for all packages who's ID appears in a screenshot's "package_id" field
subselect = Screenshot.select(:package_id)
where(id: subselect )
end
# Return a query of all packages that have screenshots
def self.without_screenshots
# Query for all packages who's ID does not appear in a screenshot's "package_id" field
subselect = Screenshot.select(:package_id)
where.not(id: subselect)
end
# Use PostgreSQL's full-text search capability for the user search
# TODO: check if pgSearch does this job for us
#def self.text_search(query)
# if query.present?
# # Add a rank column to each result
# rank = <<-RANK
# ts_rank(to_tsvector(packages.name), plainto_tsquery(#{sanitize(query)}))
# +
# ts_rank(to_tsvector(packages.description), plainto_tsquery(#{sanitize(query)}))
# RANK
#
# # Do the full-text search and return results by rank
# where("to_tsvector('english', packages.name) @@ plainto_tsquery(:q) or
# to_tsvector('english', packages.description) @@ plainto_tsquery(:q)
# ", q: query).order("#{rank} desc")
# else
# all
# end
#end
end