Sha256: da070da268ff3488659657c861d9c828df502493a59cd12361f8acb81fc9331e

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

module Chouette
  class StopPoint < TridentActiveRecord
    include ForBoardingEnumerations
    include ForAlightingEnumerations
    
    # FIXME http://jira.codehaus.org/browse/JRUBY-6358
    self.primary_key = "id"

    belongs_to :stop_area
    belongs_to :route, inverse_of: :stop_points
    has_many :vehicle_journey_at_stops, :dependent => :destroy
    has_many :vehicle_journeys, :through => :vehicle_journey_at_stops, :uniq => true
    
    acts_as_list :scope => 'route_id = \'#{route.id}\'',:top_of_list => 0

    attr_accessible :route_id, :stop_area_id, :objectid, :object_version, :creation_time, :creator_id, :position, :for_boarding, :for_alighting

    validates_presence_of :stop_area
    validate :stop_area_id_validation

    scope :default_order, order("position")
    
    before_destroy :remove_dependent_journey_pattern_stop_points
    def remove_dependent_journey_pattern_stop_points
      route.journey_patterns.each do |jp|
        if jp.stop_point_ids.include?( id)
          jp.stop_point_ids = jp.stop_point_ids - [id]
        end
      end
    end  

    def stop_area_id_validation
      if stop_area_id.nil?
        errors.add(:stop_area_id, I18n.t("errors.messages.empty"))
      end
    end

    def self.area_candidates
      Chouette::StopArea.where( :area_type => ['Quay', 'BoardingPosition'])
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ninoxe-1.1.5 app/models/chouette/stop_point.rb
ninoxe-1.1.4 app/models/chouette/stop_point.rb