Skip to content

Commit 1406180

Browse files
committed
feat(models): update slugging and associations in Calendar, Community, Conversation, and Person
1 parent a2ba1cb commit 1406180

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

app/models/better_together/calendar.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class Calendar < ApplicationRecord
1515
has_many :calendar_entries, class_name: 'BetterTogether::CalendarEntry', dependent: :destroy
1616
has_many :events, through: :calendar_entries
1717

18-
slugged :name
19-
2018
translates :name
2119
translates :description, backend: :action_text
2220

21+
slugged :name
22+
2323
def to_s
2424
name
2525
end

app/models/better_together/community.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class Community < ApplicationRecord
1919
optional: true
2020

2121
has_many :calendars, class_name: 'BetterTogether::Calendar', dependent: :destroy
22-
has_one :default_calendar, -> { where(name: 'Default') }, class_name: 'BetterTogether::Calendar'
22+
has_one :default_calendar, -> { i18n.where(name: 'Default') }, class_name: 'BetterTogether::Calendar'
2323

2424
joinable joinable_type: 'community',
2525
member_type: 'person'
2626

27-
slugged :name
28-
2927
translates :name
3028
translates :description, type: :text
3129
translates :description_html, backend: :action_text
3230

31+
slugged :name
32+
3333
has_one_attached :profile_image do |attachable|
3434
attachable.variant :optimized_jpeg, resize_to_limit: [200, 200],
3535
# rubocop:todo Layout/LineLength

app/models/better_together/conversation.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
module BetterTogether
44
# groups messages for participants
55
class Conversation < ApplicationRecord
6+
include Creatable
7+
68
encrypts :title, deterministic: true
7-
belongs_to :creator, class_name: 'BetterTogether::Person'
89
has_many :messages, dependent: :destroy
910
accepts_nested_attributes_for :messages, allow_destroy: false
1011
has_many :conversation_participants, dependent: :destroy

app/models/better_together/person.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def self.primary_community_delegation_attrs
2626

2727
has_many :conversation_participants, dependent: :destroy
2828
has_many :conversations, through: :conversation_participants
29-
has_many :created_conversations, as: :creator, class_name: 'BetterTogether::Conversation', dependent: :destroy
29+
has_many :created_conversations, foreign_key: :creator_id, class_name: 'BetterTogether::Conversation',
30+
dependent: :destroy
3031

3132
has_many :agreement_participants, class_name: 'BetterTogether::AgreementParticipant', dependent: :destroy
3233
has_many :agreements, through: :agreement_participants

0 commit comments

Comments
 (0)