Sha256: 32b17d2a7245b26f057c836791e08e11be65ee989e9a11f8d441b81048bfa447

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module Refinery
  module RaceRegistrations
    class Registration < Refinery::Core::BaseModel
      has_many   :people, :dependent => :destroy
      belongs_to :group
      has_many :categories , :through => :group  , :order=> "position DESC"


      default_scope order("position DESC")

      attr_accessible :title, :locality, :race_date, :is_active, :start_date, :end_date, :position, :group_id

      acts_as_indexed :fields => [:title, :locality]



      validates :title, :presence => true, :uniqueness => true
      validates :group_id, :presence => true

      scope :not_expired, lambda {
        registrations = Arel::Table.new(::Refinery::RaceRegistrations::Registration.table_name)
        where(registrations[:end_date].eq(nil).or(registrations[:end_date].gt(Time.now)))
      }
      scope :active, where(:is_active => true)
      scope :published, lambda {
        not_expired.active.where("start_date <= ?", Time.now).order(:position)
      }


      def to_param
        "#{id}-#{title.parameterize}"
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
refinerycms-registrations-0.1.1 app/models/refinery/race_registrations/registration.rb
refinerycms-registrations-0.1.0 app/models/refinery/race_registrations/registration.rb