docbrown/app/models/organization_membership.rb
Sebastien a25446b1d4 Add organizations to user profile (#5583) [deploy]
* Add organizations to user profile

* Add user organization info updated at column and cache key

* Remove default value for users organization_info_updated_at column

* Update organization_memberships factory

* Remove schema organization_info_updated_at default value

Co-authored-by: rhymes <rhymesete@gmail.com>
2020-01-27 13:31:27 -05:00

15 lines
517 B
Ruby

class OrganizationMembership < ApplicationRecord
belongs_to :user
belongs_to :organization
validates :user_id, :organization_id, :type_of_user, presence: true
validates :user_id, uniqueness: { scope: :organization_id }
validates :type_of_user, inclusion: { in: %w[admin member guest] }
after_create :update_user_organization_info_updated_at
after_destroy :update_user_organization_info_updated_at
def update_user_organization_info_updated_at
user.touch(:organization_info_updated_at)
end
end