Skip to content

Instantly share code, notes, and snippets.

@piperniehaus
Created March 18, 2015 15:59
Show Gist options
  • Save piperniehaus/533c20e3141673b1d2a3 to your computer and use it in GitHub Desktop.
Save piperniehaus/533c20e3141673b1d2a3 to your computer and use it in GitHub Desktop.
class Week < ActiveRecord::Base
has_many :pitch_rotation_weeks, join_table: :pitch_rotation_weeks_weeks
validates :year, presence: true
validates :month, presence: true
validates :week, presence: true
validates :start_date, presence: true
validates :week, uniqueness: {scope: [:year, :month], message: 'Year, month and week must be unique'}
validates :start_date, uniqueness: true
after_create :add_pitch_rotation_weeks_weeks
private
def add_pitch_rotation_weeks_weeks
PitchRotationWeeksWeeks.create({pitch_rotation_week_id: 27, week_id: 271})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment