Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
getfitter-core / app / models / core / organisation.rb
Size: Mime:
module Core
  class Organisation < ActiveRecord::Base
    has_many :organisation_venues, dependent: :destroy
    has_many :venues, through: :organisation_venues
    has_many :events, through: :organisation_venues
    has_many :instructors, dependent: :destroy
    has_many :passes, dependent: :destroy
    belongs_to :owner, class_name: 'User', foreign_key: 'owner_id'

    validates :name, presence: true

    before_destroy :check_for_events

    default_scope { order('created_at') }

    private

    def check_for_events
      unless events.empty?
        self.errors[:base] << 'Cannot delete Organisations with Events'

        return false
      end
    end
  end
end