Newer
Older
# id :uuid not null, primary key
# capacity :integer
# continuing :boolean
# description :text
# ects :integer
# featured_image_alt :string
# level :integer
# name :string
# path :string
# position :integer default(0)
# published :boolean default(FALSE)
# slug :string
# created_at :datetime not null
# updated_at :datetime not null
# parent_id :uuid
# university_id :uuid not null
include WithFeaturedImage
include WithBlobs
rich_text_areas_with_inheritance :accessibility,
:contacts,
:duration,
:evaluation,
:objectives,
:opportunities,
:other,
:pedagogy,
:prerequisites,
:pricing,
belongs_to :parent,
class_name: 'Education::Program',
optional: true
has_many :children,
class_name: 'Education::Program',
foreign_key: :parent_id,
has_many :teachers,
class_name: 'Education::Program::Teacher',
dependent: :destroy
has_many :university_people_through_teachers,
has_many :roles,
class_name: 'Education::Program::Role',
dependent: :destroy
has_many :role_people,
through: :roles,
has_many :university_people_through_roles,
through: :role_people,
source: :person
has_many :website_categories,
class_name: 'Communication::Website::Category',
dependent: :destroy
has_and_belongs_to_many :schools,
class_name: 'Education::School',
join_table: 'education_programs_schools',
foreign_key: 'education_program_id',
association_foreign_key: 'education_school_id'
bachelor: 300,
master: 500,
doctor: 800
}
validates_presence_of :name
after_save :update_children_paths, if: :saved_change_to_path?
after_save_commit :set_websites_categories, unless: :skip_websites_categories_callback
scope :published, -> { where(published: true) }
def best_featured_image(fallback: true)
return featured_image if featured_image.attached?
best_image = parent&.best_featured_image(fallback: false)
best_image ||= featured_image if fallback
best_image
end
def git_dependencies(website)
[self] +
active_storage_blobs +
university_people_through_teachers +
def git_destroy_dependencies(website)
[self] +
children.each do |child|
child.update_column :path, child.generated_path
child.update_children_paths
end
university.education_programs.where(parent_id: parent_id).ordered.last
end
def inherited_blob_ids
[best_featured_image&.blob_id]
end