@@ -8,12 +8,12 @@ class Event < ApplicationRecord
88 include Categorizable
99 include Creatable
1010 include FriendlySlug
11+ include Identifier
1112 include Geography ::Geospatial ::One
1213 include Geography ::Locatable ::One
13- include Identifier
14+ include Metrics :: Viewable
1415 include Privacy
1516 include TrackedActivity
16- include Viewable
1717
1818 attachable_cover_image
1919
@@ -25,6 +25,8 @@ class Event < ApplicationRecord
2525
2626 categorizable ( class_name : 'BetterTogether::EventCategory' )
2727
28+ has_many :event_hosts
29+
2830 # belongs_to :address, -> { where(physical: true, primary_flag: true) }
2931 # accepts_nested_attributes_for :address, allow_destroy: true, reject_if: :blank?
3032 # delegate :geocoding_string, to: :address, allow_nil: true
@@ -38,6 +40,10 @@ class Event < ApplicationRecord
3840 allow_nil : true
3941 validate :ends_at_after_starts_at
4042
43+ before_validation :set_host
44+
45+ accepts_nested_attributes_for :event_hosts , reject_if : :all_blank
46+
4147 scope :draft , lambda {
4248 start_query = arel_table [ :starts_at ] . eq ( nil )
4349 where ( start_query )
@@ -63,11 +69,18 @@ def self.permitted_attributes(id: false, destroy: false)
6369 starts_at ends_at registration_url
6470 ] + [
6571 {
66- address_attributes : BetterTogether ::Address . permitted_attributes ( id : true )
72+ address_attributes : BetterTogether ::Address . permitted_attributes ( id : true ) ,
73+ event_hosts_attributes : BetterTogether ::EventHost . permitted_attributes ( id : true )
6774 }
6875 ]
6976 end
7077
78+ def set_host
79+ return if event_hosts . any?
80+
81+ event_hosts . build ( host : creator )
82+ end
83+
7184 def schedule_address_geocoding
7285 return unless should_geocode?
7386
0 commit comments