Created
September 22, 2016 06:49
-
-
Save fespinoza/d5ceeb6ab3555ae7357119db8e6b81d0 to your computer and use it in GitHub Desktop.
Ruby 2.3 heredocs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Organization | |
class Group | |
# belongs_to :parent, class_name: 'Organization::Group' | |
# has_many :children, class_name: 'Organization::Group', | |
# foreign_key: :parent_id | |
# has_many :group_memberships, dependent: :destroy | |
# has_many :users, through: :group_memberships | |
RECURSIVE_UP = <<SQL.freeze | |
WITH RECURSIVE group_tree AS ( | |
SELECT g.* | |
FROM organization_groups g | |
WHERE g.id IN (?) | |
UNION | |
SELECT g.* | |
FROM organization_groups g | |
JOIN group_tree t | |
ON g.id = t.parent_id | |
) | |
SELECT * FROM group_tree t; | |
SQL | |
RECURSIVE_DOWN = <<~HEREDOC | |
WITH RECURSIVE group_tree AS ( | |
SELECT g.* | |
FROM organization_groups g | |
WHERE g.id IN (?) | |
UNION | |
SELECT g.* | |
FROM organization_groups g | |
JOIN group_tree t | |
ON g.id = t.parent_id | |
) | |
SELECT * FROM group_tree t; | |
HEREDOC | |
end | |
end |
Also thx for demo on how/where to freeze a heredoc!
👏 thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This helped me figure out how to freeze heredocs. Thanks!