topic on assotiations

Developing app, firstly I was about to set assotiations on my applications like this (I have models Test, Key and Answer).

Test has many Keys, and Key has one Answer.

So in my Test model I set assotiation to Answers like this: has_many :answers, :through => :keys.

It seems to be logic: test has many keys which have each one answer, so test has many answers through keys.

But after some testing I found out, that Rails doesn’t support this logic, because it flashed mass assigned error on key attribute, but If a added to attr_accesible :key_attributes instead of :keys_attributes, it than flashed undefined assotiation.

As API documentation says, has_many :through=>… is close to has_many_and_belongs_to_many is kind of some custom version of this.

But here is next question. What should I do? Use polymorphic or may be create simple connection between test and answers?

What do you think?

Developing app, firstly I was about to set assotiations on my applications like this (I have models Test, Key and Answer).
Test has many Keys, and Key has one Answer.

So in my Test model I set assotiation to Answers like this: has_many :answers, :through => :keys.

It seems to be logic: test has many keys which have each one answer, so test has many answers through keys.

But after some testing I found out, that Rails doesn’t support this logic, because it flashed mass assigned error on key attribute, but If a added to attr_accesible :key_attributes instead of :keys_attributes, it than flashed undefined assotiation.

That sounds like it should work. What did your code look like ? http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html has examples of the various supported scenarios.

Fred