cybertooth-io / ermahgerd-rails-api-jwt

Rails 5+ API, JWT_Session, Pundit, JSONAPI, Sidekiq, PostgreSQL.
0 stars 0 forks source link

Last Activities VIEW #25

Open nadnoslen opened 6 years ago

nadnoslen commented 6 years ago

It's always nice to have the last of some user. For example, last seen would be the USERS' most recently created SESSION_ACTIVITIES record. This could be a column derived in a VIEW and could easily be rendered as a relationship to a USERS record.

CREATE VIEW users_last_activities AS
SELECT users.id,
(
  SELECT MAX(sa.created_at) 
  FROM session_activities sa INNER JOIN sessions s
  ON sa.session_id=s.id
  WHERE s.user_id=users.id
),
...
FROM users

Other last ideas from projects I've worked on: