Has_many through - getting the parent

has_many :through is great. Is there anyway to find the association
that it went through?

Example:

class Student
has_many :projects
has_many :grades, :through => :projects
end

student.grades[3].project

Is it clear what I’m asking? How would this be done?

Robert J. wrote:

student.grades[3].project

Is it clear what I’m asking? How would this be done?

I’ve been playing around with the same thing today. Here’s what I know
so far…

grade[3].find_all_in_projects([“student_id = ?”, student.id)

should return an array of projects associated with this grade and
student. I’m still trying to nail down a more elegant way to get at that
join object. Let me know if you figure out anything useful.

Robert J. wrote:

has_many :through is great. Is there anyway to find the association
that it went through?

Example:

class Student
has_many :projects
has_many :grades, :through => :projects
end

student.grades[3].project

Is it clear what I’m asking? How would this be done?

I just wrote something up on this a few hours ago:

http://blog.hasmanythrough.com/articles/2006/06/30/working-with-the-relationship-model


Josh S.
http://blog.hasmanythrough.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs