You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: relatable.rb
    path of file: ./repos/openproject/app/models/work_packages/scopes
    
    the code of the file until where you have to start completion: #  OpenProject is an open source project management software.
#  Copyright (C) 2010-2022 the OpenProject GmbH
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License version 3.
#
#  OpenProject is a fork of ChiliProject, which is a fork of Redmine.
    
      def existing_hierarchy_lateral(with_descendants: true)
        <<~SQL.squish
          SELECT
            CASE
              WHEN work_package_hierarchies.ancestor_id = related.id
              THEN work_package_hierarchies.descendant_id
              ELSE work_package_hierarchies.ancestor_id
              END id,
            true from_hierarchy,
            false from_from_id,
            false from_to_id,
            related.includes_from_relation,
            related.includes_to_relation,
            #{with_descendants ? 'work_package_hierarchies.descendant_id = related.id' : 'work_package_hierarchies.ancestor_id = related.id'} includes_hierarchy
          FROM
            work_package_hierarchies
          WHERE
            related.from_hierarchy = false AND
            (work_package_hierarchies.descendant_id = related.id OR work_package_hierarchies.ancestor_id = related.id)
            AND (work_package_hierarchies.generations != 0)
        SQL
      end