Add circle editor
This commit is contained in:
parent
c97e63bb18
commit
b0854b1dd8
33 changed files with 1671 additions and 31 deletions
29
app/models/circle.rb
Normal file
29
app/models/circle.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: circles
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8) not null
|
||||
# title :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class Circle < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
PER_ACCOUNT_LIMIT = 100
|
||||
|
||||
belongs_to :account
|
||||
|
||||
has_many :circle_accounts, inverse_of: :circle, dependent: :destroy
|
||||
has_many :accounts, through: :circle_accounts
|
||||
|
||||
validates :title, presence: true
|
||||
|
||||
validates_each :account_id, on: :create do |record, _attr, value|
|
||||
record.errors.add(:base, I18n.t('lists.errors.limit')) if List.where(account_id: value).count >= PER_ACCOUNT_LIMIT
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue