Skip to content

Commit

Permalink
Merge pull request #1546 from noesya/categories-no-path
Browse files Browse the repository at this point in the history
Réparation du chemin des catégories d'événement
  • Loading branch information
arnaudlevy committed Jan 17, 2024
2 parents 7605d1f + 861d075 commit 5f7f307
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions app/models/communication/website/agenda/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
# communication_website_id :uuid not null, indexed
# language_id :uuid not null, indexed
# original_id :uuid indexed
# parent_id :uuid indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# idx_communication_website_agenda_cats_on_website_id (communication_website_id)
# index_communication_website_agenda_categories_on_language_id (language_id)
# index_communication_website_agenda_categories_on_original_id (original_id)
# index_communication_website_agenda_categories_on_parent_id (parent_id)
# index_communication_website_agenda_categories_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_1e1b9fbf33 (original_id => communication_website_agenda_categories.id)
# fk_rails_692dbf7723 (parent_id => communication_website_agenda_categories.id)
# fk_rails_6cb9a4b8a1 (university_id => universities.id)
# fk_rails_7b5ad84dda (communication_website_id => communication_websites.id)
# fk_rails_b0ddee638d (language_id => languages.id)
Expand All @@ -45,12 +48,17 @@ class Communication::Website::Agenda::Category < ApplicationRecord
include WithTranslations
include WithUniversity

belongs_to :parent,
class_name: 'Communication::Website::Agenda::Category',
optional: true
has_and_belongs_to_many :events,
class_name: 'Communication::Website::Agenda::Event',
join_table: :communication_website_agenda_events_categories,
foreign_key: :communication_website_agenda_category_id,
association_foreign_key: :communication_website_agenda_event_id

validates :name, presence: true

def to_s
"#{name}"
end
Expand Down
1 change: 0 additions & 1 deletion app/models/communication/website/post/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Communication::Website::Post::Category < ApplicationRecord
include WithTree
include WithUniversity

belongs_to :university
belongs_to :parent,
class_name: 'Communication::Website::Post::Category',
optional: true
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/with_slug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def slug_unavailable?(slug)
.exists?
end

# FIXME `respond_to?(:parent)` sert à quoi ?
def make_path
return unless respond_to?(:path) && respond_to?(:parent)
self.path = generated_path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddParentToCommunicationWebsiteAgendaCategories < ActiveRecord::Migration[7.1]
def change
add_reference :communication_website_agenda_categories, :parent, foreign_key: {to_table: :communication_website_agenda_categories}, type: :uuid
end
end
5 changes: 4 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/communication/website/agenda/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
# communication_website_id :uuid not null, indexed
# language_id :uuid not null, indexed
# original_id :uuid indexed
# parent_id :uuid indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# idx_communication_website_agenda_cats_on_website_id (communication_website_id)
# index_communication_website_agenda_categories_on_language_id (language_id)
# index_communication_website_agenda_categories_on_original_id (original_id)
# index_communication_website_agenda_categories_on_parent_id (parent_id)
# index_communication_website_agenda_categories_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_1e1b9fbf33 (original_id => communication_website_agenda_categories.id)
# fk_rails_692dbf7723 (parent_id => communication_website_agenda_categories.id)
# fk_rails_6cb9a4b8a1 (university_id => universities.id)
# fk_rails_7b5ad84dda (communication_website_id => communication_websites.id)
# fk_rails_b0ddee638d (language_id => languages.id)
Expand Down
3 changes: 3 additions & 0 deletions test/models/communication/website/agenda/category_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
# communication_website_id :uuid not null, indexed
# language_id :uuid not null, indexed
# original_id :uuid indexed
# parent_id :uuid indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# idx_communication_website_agenda_cats_on_website_id (communication_website_id)
# index_communication_website_agenda_categories_on_language_id (language_id)
# index_communication_website_agenda_categories_on_original_id (original_id)
# index_communication_website_agenda_categories_on_parent_id (parent_id)
# index_communication_website_agenda_categories_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_1e1b9fbf33 (original_id => communication_website_agenda_categories.id)
# fk_rails_692dbf7723 (parent_id => communication_website_agenda_categories.id)
# fk_rails_6cb9a4b8a1 (university_id => universities.id)
# fk_rails_7b5ad84dda (communication_website_id => communication_websites.id)
# fk_rails_b0ddee638d (language_id => languages.id)
Expand Down

0 comments on commit 5f7f307

Please sign in to comment.