Sha256: d960c5e3965f7ab80f0cbe87376e0472f9a1100e3ad211ec81d420edc698b970
Contents?: true
Size: 1.33 KB
Versions: 22
Compression:
Stored size: 1.33 KB
Contents
# assoc_test.rb path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys")) puts path require File.join(path) require 'active_record' $configuration = { :adapter => 'postgresql', :database => 'cpk_test', :username => 'postgres' } ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected? module GlobePG class PGBase < ActiveRecord::Base self.abstract_class = true # establish_connection($configuration) unless connected? end end module GlobePG class TeacherToSchool < PGBase set_table_name 'teacher_to_school' set_primary_keys ['teacherid', 'schoolid'] belongs_to :globe_teacher, :foreign_key => 'teacherid' belongs_to :globe_school, :foreign_key => 'schoolid' end end module GlobePG class GlobeSchool < PGBase set_table_name 'globe_school' set_primary_key 'schoolid' has_many :teacher_to_schools, :foreign_key => :schoolid has_many :globe_teachers, :through => :teacher_to_schools end end module GlobePG class GlobeTeacher < PGBase set_table_name 'globe_teacher' set_primary_key 'teacherid' has_many :teacher_to_schools, :foreign_key => :teacherid has_many :globe_schools, :through => :teacher_to_schools end end teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY') p teacher.globe_schools
Version data entries
22 entries across 22 versions & 1 rubygems