2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
class ChildTheme < ActiveRecord::Base
|
|
|
|
belongs_to :parent_theme, class_name: "Theme"
|
|
|
|
belongs_to :child_theme, class_name: "Theme"
|
2018-08-08 12:46:34 +08:00
|
|
|
|
|
|
|
validate :child_validations
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def child_validations
|
2018-08-24 09:30:00 +08:00
|
|
|
if Theme.where(
|
|
|
|
"(component IS true AND id = :parent) OR (component IS false AND id = :child)",
|
|
|
|
parent: parent_theme_id,
|
|
|
|
child: child_theme_id,
|
|
|
|
).exists?
|
2018-08-08 12:46:34 +08:00
|
|
|
errors.add(:base, I18n.t("themes.errors.no_multilevels_components"))
|
|
|
|
end
|
|
|
|
end
|
2017-04-12 22:52:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: child_themes
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# parent_theme_id :integer
|
|
|
|
# child_theme_id :integer
|
2019-01-12 03:29:56 +08:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2017-04-12 22:52:52 +08:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_child_themes_on_child_theme_id_and_parent_theme_id (child_theme_id,parent_theme_id) UNIQUE
|
|
|
|
# index_child_themes_on_parent_theme_id_and_child_theme_id (parent_theme_id,child_theme_id) UNIQUE
|
|
|
|
#
|