i have an internal app being used for tracking internal jobs inside
the shop. the company has multiple divisions, and transfers jobs back
and forth between divisions. each division has their own job numbering
scheme as well.
what i’ve done is set up a jobs table which has many job_tags, which
is the table i use to store the job number and other specific info
relating to that division. so each time i am displaying a job, to also
get a it’s job_tag i started out with something like this:
job.job_tags.find_by_division_id(@division.id).name
to prevent the database getting hit each time on finding multiple
jobs, i have something like this in the controller:
jobs = Job.find(:all, :include => :job_tags, :conditions =>
[‘job_tags.division_id = ?’, @division.id])
and in the view i use:
job.job_tags.first.name
this is proving to not be very flexible and any time i have to change
the list ever so slightly for another page, i find myself duplicating
a lot of code. ideally i would like to add something like
has_one :job_tag, :condititions => [‘job_tags.division_id = ?’,
division.id]
to my Job model and be able to pass the current division to it, or if
there are better ways to manage this type of thing, i am very open to
any suggestions.