jeudi 24 mars 2016

A small puzzle of Rails Associations

There are 2 tables. One is User(id, name, email) and the other is Student(id, who_id).

I wanna Use this way:

Student.find(id).name, Student.find(id).email

rather than:

User.find(student.who_id).name, User.find(student.who_id).email

to get data.

How should I do?

btw, I cannot change who_id to user_id for any reason.


class User < ActiveRecord::Base
end

class Student < ActiveRecord::Base
end

Aucun commentaire:

Enregistrer un commentaire