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: activity.rb
    path of file: ./repos/openproject/app/models/projects
    
    the code of the file until where you have to start completion: #-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms 
    
    def build_latest_project_activity_for(on:, chain:, attribute:, project_id_attribute:)
      join_chain = Array(chain).dup.push(on)
      from = join_chain.first

      joins = build_joins_from_chain(join_chain)

      <<-SQL
        SELECT #{project_id_attribute} project_id, MAX(#{on.table_name}.#{attribute}) updated_at
        FROM #{from.table_name}
        #{joins.join(' ')}
        WHERE #{on.table_name}.#{attribute} IS NOT NULL
        GROUP BY project_id
      SQL
    end