Skip to content

Instantly share code, notes, and snippets.

@jvnill
Created November 21, 2012 15:06
Show Gist options
  • Save jvnill/4125299 to your computer and use it in GitHub Desktop.
Save jvnill/4125299 to your computer and use it in GitHub Desktop.
Core associations between contract, client, code and codeline
class Client < ActiveRecord::Base
attr_accessible :etc, :firstname, :lastname, :mi
has_many :contracts
validates :firstname, :lastname, :mi, presence: true
def full_name
"#{firstname} #{mi} #{lastname}"
end
end
class Code < ActiveRecord::Base
attr_accessible :codename, :description, :status
has_many :codelines, dependent: :destroy
has_many :contracts, through: :codelines
validates :codename, :description, :status, presence: true
end
class Codeline < ActiveRecord::Base
belongs_to :contract
belongs_to :code
accepts_nested_attributes_for :code
attr_accessible :code_attributes, :units_alloc
validates :units_alloc, presence: true, numericality: true
end
class Contract < ActiveRecord::Base
belongs_to :client
has_many :codelines, dependent: :destroy
has_many :codes, through: :codelines
accepts_nested_attributes_for :codelines
accepts_nested_attributes_for :client
validates :authnum, :end_date, :start_date, presence: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment