class SportDb::Sync::Round
Public Class Methods
find_or_create( round, event: )
click to toggle source
# File lib/sportdb/sync/sync.rb, line 66 def self.find_or_create( round, event: ) rec = Model::Round.find_by( name: round.name, event_id: event.id ) if rec.nil? ## find last pos - check if it can be nil? max_pos = Model::Round.where( event_id: event.id ).maximum( 'pos' ) max_pos = max_pos ? max_pos+1 : 1 attribs = { event_id: event.id, name: round.name, pos: max_pos } ## todo/fix: check if round has (optional) start or end date and add!!! ## attribs[ :start_date] = round.start_date.to_date rec = Model::Round.create!( attribs ) end rec end