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
rich_text_areas_with_inheritance :accessibility,
:contacts,
:duration,
:evaluation,
:objectives,
:opportunities,
:other,
:pedagogy,
:prerequisites,
:pricing,
:registration
belongs_to :parent,
class_name: 'Education::Program',
optional: true
has_many :children,
class_name: 'Education::Program',
foreign_key: :parent_id,
has_many :members,
class_name: 'Education::Program::Member',
dependent: :destroy,
inverse_of: :program
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'
join_table: 'education_programs_teachers',
foreign_key: 'education_program_id',
association_foreign_key: 'education_teacher_id'
accepts_nested_attributes_for :members, allow_destroy: true
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_static
active_storage_blobs
end
children.each do |child|
child.update_column :path, child.generated_path
child.update_children_paths
end