Listing 1. Model Files, with Associations and Validations

class Person < ActiveRecord::Base
  has_many :meeting_people
  has_many :meetings, :through => :meeting_people

  validates_presence_of :first_name, :last_name, :email
  validates_uniqueness_of :email

  def fullname
    "#{first_name} #{last_name}"
  end

end


class Meeting < ActiveRecord::Base
  has_many :meeting_people
  has_many :people, :through => :meeting_people

  validates_presence_of :starting_at, :ending_at, :location

  def validate
    if starting_at > ending_at
      errors.add_to_base("Starting time is later than ending time!")
    end

    if self.people.empty?
      errors.add_to_base("You must meet with at least one person!")
    end
  end

  def people_as_sentence
    return self.people.map { |p| p.fullname}.to_sentence
  end

end

class MeetingPerson < ActiveRecord::Base
  belongs_to :person
  belongs_to :meeting

end