Last active
April 24, 2025 19:16
-
-
Save lazaronixon/142c6e7efbdf97c01bf6cc0b9205a91c to your computer and use it in GitHub Desktop.
has_one_latest_by
This file contains hidden or 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
class Member | |
has_one :latest_activity, -> { from(Activity.latest_by_member, :activities) }, class_name: "Activity" | |
end | |
class Activity | |
scope :latest_by_member, -> { select("DISTINCT ON (member_id) *").order(:member_id, created_at: :desc) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rails/rails#41622