module Qcourses class Location < Sequel::Model plugin :validation_helpers one_to_many :events def validate validates_presence :name end def self.find_or_create_bij_insensitive_name(new_location) return nil if new_location.empty? filter(:name.ilike("#{new_location}%") ).first || create(name: new_location) end end end