Forum: Ruby on Rails topic on assotiations

Posted by Barry (Guest)
on 2013-03-14 13:58
(Received via mailing list)
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?
Posted by Frederick Cheung (Guest)
on 2013-03-14 15:08
(Received via mailing list)
On Thursday, March 14, 2013 12:57:32 PM UTC, Barry wrote:
> 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/As...
has examples of the various supported scenarios.

Fred
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.