Class: SportDb::Sync::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/readers/sync/more.rb

Class Method Summary collapse

Class Method Details

.find_or_create(group, event:) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sportdb/readers/sync/more.rb', line 88

def self.find_or_create( group, event: )
   rec = Model::Group.find_by( name: group.name, event_id: event.id )
   if rec.nil?
     ## find last pos - check if it can be nil?
     max_pos = Model::Group.where( event_id: event.id ).maximum( 'pos' )
     max_pos = max_pos ? max_pos+1 : 1

     attribs = { event_id: event.id,
                 name:     group.name,
                 pos:      max_pos
               }

     ## todo/fix: check/add optional group key (was: pos before)!!!!
     rec = Model::Group.create!( attribs )
   end
   ## todo/fix: add/update teams in group too!!!!!
   rec
end