Skip to content

Instantly share code, notes, and snippets.

@alextoul
Created November 13, 2018 14:21
Show Gist options
  • Save alextoul/8e12f7c1fb0a35027e20b2d7140e3a42 to your computer and use it in GitHub Desktop.
Save alextoul/8e12f7c1fb0a35027e20b2d7140e3a42 to your computer and use it in GitHub Desktop.
user.rb
has_one :profile_pictures_album, ->{ where "media_albums.permalink = 'profile_pictures'" }, class_name: 'Media::Album', as: :owner
has_one :cover_photos_album, ->{ where "media_albums.permalink = 'cover_photos'" }, class_name: 'Media::Album', as: :owner
has_one :uploads_photos_album, ->{ where "media_albums.permalink = 'uploads'" }, class_name: 'Media::Album', as: :owner
has_one :location, ->{ where '`social_locations`.`default` = true' }, class_name: 'Social::Location'
has_one :email_address, ->{ where default: true }, class_name: 'Auth::EmailAddress'
has_many :email_addresses, class_name: 'Auth::EmailAddress', dependent: :destroy
has_many :verified_email_addresses, ->{ where.not(verified_at: nil) }, class_name: 'Auth::EmailAddress', dependent: :destroy
has_many :devices, class_name: 'Auth::Device', dependent: :destroy
has_many :grants, class_name: 'Auth::Grant', dependent: :destroy
has_many :apps, foreign_key: :user_id, class_name: 'Auth::App', dependent: :destroy
has_many :authorized_apps, class_name: 'Auth::App', through: :grants
has_many :sent_messages, class_name: 'Social::Message', foreign_key: :user_id, dependent: :destroy
has_many :received_messages, class_name: 'Social::Message', foreign_key: :recipient_id, dependent: :destroy
has_many :notifications, class_name: 'Notify::Notification', dependent: :destroy
has_many :subscriptions, class_name: 'Notify::Subscription', dependent: :destroy
has_many :statuses, class_name: 'Social::Status', dependent: :destroy
has_many :posts, ->{ where 'parent_type IS NULL' }, class_name: 'Social::Status', dependent: :destroy
has_many :recent_posts, ->{ limit(20).order(created_at: :desc).where(parent_type: nil) }, class_name: 'Social::Status', dependent: :destroy
has_many :likes, class_name: 'Social::Like', dependent: :destroy
has_many :liked_statuses, class_name: 'Social::Status', through: :likes
has_many :locations, class_name: 'Social::Location', dependent: :destroy
has_many :follows, class_name: 'Social::Follow', foreign_key: :follower_id, dependent: :destroy
has_many :allowed_follows, ->{ where 'blocked_at IS NULL' }, class_name: 'Social::Follow', foreign_key: :follower_id
has_many :blocked_follows, ->{ where 'blocked_at IS NOT NULL' }, class_name: 'Social::Follow', foreign_key: :follower_id
has_many :follower_follows, ->{ where 'blocked_at IS NULL' }, class_name: 'Social::Follow', foreign_key: :followee_id, dependent: :destroy
has_many :followed_users, through: :allowed_follows, source: :followee, foreign_key: :follower_id, class_name: 'User'
has_many :blocked_users, through: :blocked_follows, source: :followee, foreign_key: :follower_id, class_name: 'User'
has_many :followers, through: :follower_follows, source: :follower, foreign_key: :followee_id, class_name: 'User'
has_many :albums, as: :owner, class_name: 'Media::Album', dependent: :destroy
has_many :gear_posts, class_name: 'Marketplace::GearPost', dependent: :destroy
has_many :memberships, class_name: 'Teams::Membership', dependent: :destroy
has_many :captaincies, ->{ where(captain: 'C') }, class_name: 'Teams::Membership', dependent: :destroy
has_many :suspensions, class_name: 'Teams::Suspension', through: :memberships
has_many :registrations, ->{ order(:updated_at) }, class_name: 'Teams::Registration', through: :memberships
has_many :divisions, class_name: 'Leagues::Division', through: :registrations
has_many :seasons, class_name: '::Leagues::Season', through: :divisions
has_many :leagues, class_name: 'Leagues::League', through: :seasons
has_many :league_teams, ->{ joins(registrations: :memberships).order('teams_memberships.created_at DESC') }, class_name: 'Teams::Team', through: :registrations, source: :team
has_many :teams, ->{ joins(:memberships).order('teams_memberships.created_at DESC') }, class_name: 'Teams::Team', through: :memberships
has_many :teammate_memberships, class_name: 'Teams::Membership', through: :registrations, source: :memberships
has_many :teammates, class_name: 'User', through: :teammate_memberships, source: :user
has_many :league_attendances, class_name: 'Games::GameAttendance', through: :memberships, source: :attendances
has_many :league_attended_games, class_name: 'Games::Game', through: :league_attendances, source: :game
has_many :league_attended_icetimes, class_name: 'Arenas::Icetime', through: :league_attended_games, source: :icetime
has_many :league_attended_rinks, class_name: 'Arenas::Rink', through: :league_attended_icetimes, source: :rink
has_many :league_attended_arenas, class_name: 'Arenas::Arena', through: :league_attended_rinks, source: :arena
has_many :event_attendances, class_name: 'Games::EventAttendance'
has_many :events_attending, class_name: 'Games::Event', through: :event_attendances, source: :event
has_many :organizer_attendances, ->{ where(organizer: true) }, class_name: 'Games::EventAttendance'
has_many :regular_attendances, ->{ where.not(organizer: true) }, class_name: 'Games::EventAttendance'
has_many :recent_regular_attendances, ->{ where(['games_event_attendances.confirmed_at > ?', 3.months.ago]).where.not(organizer: true) }, class_name: 'Games::EventAttendance'
has_many :events_organized, class_name: 'Games::Event', through: :organizer_attendances, source: :event
has_many :event_attended_icetimes, class_name: 'Arenas::Icetime', through: :events_attending, source: :icetime
has_many :event_attended_rinks, class_name: 'Arenas::Rink', through: :event_attended_icetimes, source: :rink
has_many :event_attended_arenas, class_name: 'Arenas::Arena', through: :event_attended_rinks, source: :arena
has_many :profile_pictures, class_name: 'Media::Photo', through: :profile_pictures_album, source: :photos
has_many :cover_photos, class_name: 'Media::Photo', through: :cover_photos_album, source: :photos
has_many :brands, class_name: 'Marketplace::Brand', dependent: :destroy
has_many :managed_teams, class_name: 'Teams::Team', foreign_key: :manager_id, dependent: :restrict_with_exception
has_many :user_sports, class_name: 'Auth::UserSport', dependent: :destroy
has_many :sports, through: :user_sports, class_name: 'Games::Sport'
has_many :oauth_identifiers, class_name: 'Auth::OauthIdentifier', dependent: :destroy
has_many :employments, class_name: 'Org::Staff', dependent: :destroy
has_many :assignments, class_name: 'Org::Assignment', dependent: :destroy, through: :employments
has_many :league_assignments, ->{ where(target_type: 'Leagues::League') }, class_name: 'Org::Assignment', dependent: :destroy, through: :employments, source: :assignments
has_many :assigned_leagues, class_name: 'Leagues::League', dependent: :destroy, through: :league_assignments, source: :target, source_type: 'Leagues::League'
has_many :invoices, class_name: 'Billing::Invoice'
has_many :newsfeed_preferences, class_name: 'Social::NewsfeedPreference', dependent: :destroy
has_many :player_requests, class_name: 'TeamFinder::PlayerRequest', dependent: :destroy
has_many :team_requests, class_name: 'TeamFinder::TeamRequest', dependent: :destroy
has_many :organizer_policies, class_name: 'Games::OrganizerPolicy', foreign_key: :organizer_id, dependent: :destroy
has_many :applied_organizer_policies, class_name: 'Games::OrganizerPolicy', foreign_key: :user_id, dependent: :destroy
has_many :coach_mark_views, class_name: 'Notify::CoachMarkView', dependent: :destroy
has_many :viewed_coach_marks, class_name: 'Notify::CoachMark', through: :coach_mark_views, source: :coach_mark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment