Help! I'm trying to use composed_of to pull from multiple classes and
can't figure out if it is possible or if there might be a better way
to accomplish what i want.
I created standard_grade_strand_number, which references items in
class Standard. HOWEVER, I don't want to see the the grade_id and
strand_id in class Standard. I want to see the grade.name and
strand.name in their respective classes.
Here's what I have (but not exactly what I want):
(model)
class Standard < ActiveRecord::Base
belongs_to :grade
belongs_to :strand
composed_of :standard_grade_strand_number,
:mapping => [ %w[grade_id grade_id],
%w[strand_id strand_id],
%w[number number] ]
(model)
class StandardGradeStrandNumber < ActiveRecord::Base
attr_reader :grade_id, :strand_id, :number
def initialize(grade_id, strand_id, number)
@grade_id = grade_id
@strand_id = strand_id
@number = number
end
def to_s
[ @grade_id, @strand_id, @number ].compact.join("")
end
end
Oh, here are the Strand and Grade models:
class Grade < ActiveRecord::Base
has_many :standards
class Strand < ActiveRecord::Base
has_many :standards
I've tried putting grade.name and strand.name in
standard_grade_strand_number but can't make it work.
Do you have any ideas? Any thoughts? Do you see a better way to
accomplish what I want? Thank you in advance!!!