mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-21 19:22:18 -05:00
23 lines
519 B
Ruby
23 lines
519 B
Ruby
class Group < ApplicationRecord
|
|
include CaberSubject
|
|
|
|
belongs_to :creator
|
|
validates :name, presence: true
|
|
|
|
has_many :memberships, dependent: :destroy
|
|
has_many :members, through: "memberships", source: :user
|
|
|
|
accepts_nested_attributes_for :memberships, reject_if: :all_blank, allow_destroy: true
|
|
|
|
def typed_id
|
|
"group::#{id}"
|
|
end
|
|
|
|
TYPED_ID_PATTERN = /group::([[:digit:]]+)/
|
|
|
|
def self.find_by_typed_id(typed_id, scope: Group)
|
|
typed_id.match(TYPED_ID_PATTERN)
|
|
scope.find($1) if $1
|
|
end
|
|
end
|