Here is my DB Schema. NOTE the 'studentid' and 'student_studentid'
create_table "students", force: true do |t|
t.string "fname", limit: 45
t.string "lname", limit: 45
t.string "guardian", limit: 45
t.string "phone", limit: 45
t.string "email", limit: 45
t.integer "user_id"
t.date "createdate"
t.string "studentid", limit: 45
end
create_table "term_reports", force: true do |t|
t.string "student_studentid", limit: 10
t.integer "subject_id"
t.integer "score"
t.integer "position"
t.integer "term"
t.integer "year"
t.integer "user_id"
t.date "ceatedate"
end
I am assigning custom id's to the students. How can I use these columns for table associations? I want to be able to say TermReport.find('my-id-10').student.
Here is what I have tried but wont work.
class TermReport < ActiveRecord::Base
belongs_to :student, :primary_key => :studentid
end
class Student < ActiveRecord::Base
has_many :term_reports, primary_key: :stuent_studentid
end