2023-02-03 11:44:40 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SidebarSection < ActiveRecord::Base
|
2023-03-27 10:03:16 +08:00
|
|
|
MAX_TITLE_LENGTH = 30
|
|
|
|
|
2023-02-03 11:44:40 +08:00
|
|
|
belongs_to :user
|
2023-03-21 09:23:28 +08:00
|
|
|
has_many :sidebar_section_links, -> { order("position") }, dependent: :destroy
|
2023-02-03 11:44:40 +08:00
|
|
|
has_many :sidebar_urls,
|
|
|
|
through: :sidebar_section_links,
|
|
|
|
source: :linkable,
|
|
|
|
source_type: "SidebarUrl"
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :sidebar_urls, allow_destroy: true
|
|
|
|
|
2023-03-27 10:03:16 +08:00
|
|
|
validates :title,
|
|
|
|
presence: true,
|
|
|
|
uniqueness: {
|
|
|
|
scope: %i[user_id],
|
|
|
|
},
|
|
|
|
length: {
|
|
|
|
maximum: MAX_TITLE_LENGTH,
|
|
|
|
}
|
2023-02-03 11:44:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: sidebar_sections
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# user_id :integer not null
|
2023-02-08 08:45:34 +08:00
|
|
|
# title :string(30) not null
|
2023-02-03 11:44:40 +08:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2023-02-22 05:55:44 +08:00
|
|
|
# public :boolean default(FALSE), not null
|
2023-02-03 11:44:40 +08:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_sidebar_sections_on_user_id_and_title (user_id,title) UNIQUE
|
|
|
|
#
|