Hi,
I'm new to rails and so far think it's great, but I'm having some major issues with a many-through relationship.
There are three tables: reporttemplates articlestemplates_reporttemplates (additional attribute "optional") articletemplates
They are connected to each other via has_many and through + belongs_to in articlestemplates_reporttemplates.
Now, I need to display all articletemplates and show, if there is a connection (entry in articlestemplates_reporttemplates) to the current reporttemplate. So in the controller I call @articletemplates = Articletemplate.find(:all, :joins=>"LEFT JOIN articletemplates_reporttemplates ON `articletemplates_reporttemplates`.articletemplate_id = `articletemplates`.id WHERE `articletemplates_reporttemplates`.reporttemplate_id = "+params[:id])
So far, everything is working. When I call <% puts YAML::dump(articletemplate.articletemplates_reporttemplates) %> in the view, it gives me: - !ruby/object:ArticletemplatesReporttemplate attributes: created_at: 2008-12-16 17:24:19 optional: "0" updated_at: 2008-12-16 17:24:19 id: "1" reporttemplate_id: "1" articletemplate_id: "1" attributes_cache: {}
But when I try to access the attribute "optional", I always get an error message! <% if articletemplate.articletemplates_reporttemplates.optional == 0 %> leads to "undefined method `optional' for #<Class:0x7f83e7451880>"
Why does it tell me "undefined", when one line above it tells me there is an attribute "optional"?
Any help is appreciated!
Best Regards, Daniel Süpke