Created
November 6, 2009 18:11
-
-
Save turnerking/228155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job < ActiveRecord::Base | |
has_many :requirements | |
has_many :required_jobs, :source => :derived_job, :through => :requirements | |
has_many :derived_jobs, :source => :required_job, :through => :requirements | |
end | |
class Requirement < ActiveRecord::Base | |
belongs_to :derived_job, :class_name => "Job" | |
belongs_to :required_job, :class_name => "Job" | |
end | |
SQL produced on Job.first.derived_jobs | |
SELECT `jobs`.* FROM `jobs` INNER JOIN `requirements` ON `jobs`.id = `requirements`.required_job_id WHERE ((`requirements`.job_id = 1)) | |
#Why is the association producing job_id versus required_job_id in the where clause, do I need to do a custom finder_sql for the relationship? | |
#Data Structure | |
#There is a Job in order to be able to do another Job you need to be at a certain level in your current job(s), so a job has many required jobs where the relationship holds the level where you need to be in order to do the current job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment