From 8ad93f9923051381b16e2df11233ee5f940e067e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 15 Nov 2024 16:31:16 -0500 Subject: [PATCH] Add `access_tokens` association for `User` --- app/models/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 07f67c35ab..0237750221 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,6 +89,7 @@ class User < ApplicationRecord accepts_nested_attributes_for :account has_many :applications, class_name: 'Doorkeeper::Application', as: :owner, dependent: nil + has_many :access_tokens, class_name: 'Doorkeeper::AccessToken', foreign_key: :resource_owner_id, dependent: nil, inverse_of: false has_many :backups, inverse_of: :user, dependent: nil has_many :invites, inverse_of: :user, dependent: nil has_many :markers, inverse_of: :user, dependent: :destroy @@ -281,8 +282,7 @@ class User < ApplicationRecord end def applications_last_used - Doorkeeper::AccessToken - .where(resource_owner_id: id) + access_tokens .used .group(:application_id) .maximum(:last_used_at)