Skip to content

Commit

Permalink
Merge pull request #1036 from bgeuken/cleanup_sql_query
Browse files Browse the repository at this point in the history
[api][webui] Make SQL statement more readable by using heredoc
  • Loading branch information
hennevogel committed Aug 18, 2015
2 parents 2cc850c + c45609d commit c1881c9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/api/app/models/channel_binary.rb
Expand Up @@ -15,10 +15,16 @@ def self.find_by_project_and_package(project, package)
# find maintained projects filter
maintained_projects = Project.get_maintenance_project.expand_maintained_projects

# rubocop:disable Metrics/LineLength
# I am not able to construct this with rails in a valid way :/
ChannelBinary.find_by_sql(['SELECT channel_binaries.* FROM channel_binaries LEFT JOIN channel_binary_lists ON channel_binary_lists.id = channel_binaries.channel_binary_list_id LEFT JOIN channels ON channel_binary_lists.channel_id = channels.id LEFT JOIN packages ON channels.package_id = packages.id WHERE (channel_binary_lists.project_id = ? and package = ? and packages.project_id IN (?))', project.id, package, maintained_projects])
# rubocop:enable Metrics/LineLength
# gsub(/\s+/, "") makes sure there are no additional newlines and whitespaces
query = <<-SQL.gsub(/\s+/, " ")
SELECT channel_binaries.* FROM channel_binaries
LEFT JOIN channel_binary_lists ON channel_binary_lists.id = channel_binaries.channel_binary_list_id
LEFT JOIN channels ON channel_binary_lists.channel_id = channels.id
LEFT JOIN packages ON channels.package_id = packages.id WHERE (
channel_binary_lists.project_id = ? and package = ? and packages.project_id IN (?)
)
SQL
ChannelBinary.find_by_sql([query, project.id, package, maintained_projects])
end

def create_channel_package_into(project, comment=nil)
Expand Down

0 comments on commit c1881c9

Please sign in to comment.