{"id":1092,"date":"2022-08-30T15:12:15","date_gmt":"2022-08-30T15:12:15","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/can-i-use-has_many-through-and-dependent-destroy-together-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:15","modified_gmt":"2022-08-30T15:12:15","slug":"can-i-use-has_many-through-and-dependent-destroy-together-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/can-i-use-has_many-through-and-dependent-destroy-together-collection-of-common-programming-errors\/","title":{"rendered":"Can I use has_many :through and :dependent =&gt; destroy together?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to run a functional test on my PollsController and keep getting this error:<\/p>\n<pre><code>block in assert_valid_keys': Unknown key: through (ArgumentError)\n<\/code><\/pre>\n<p>I&#8217;m wondering if its because I have a dependent destroy on the Question model and a has_many relationship ship through it to sms. Any advice? Thanks!!<\/p>\n<p><strong>Here&#8217;s the Poll model<\/strong><\/p>\n<pre><code>class Poll &lt; ActiveRecord::Base\n  attr_accessible :description, :end_time, :start_time, :title, :user_id, :questions_attributes, :is_live\n\n  belongs_to :user\n  has_many :questions, :dependent =&gt; :destroy\n  # This is the pluralized form of sms, it's not smss\n  has_many :sms, :through =&gt; :questions \n  has_many :feedbacks\n\n  accepts_nested_attributes_for :questions, :allow_destroy =&gt; true\n<\/code><\/pre>\n<p><strong>Question model<\/strong><\/p>\n<pre><code>class Question &lt; ActiveRecord::Base\n  attr_accessible :poll_id, :title, :answers_attributes\n\n  belongs_to :poll\n  has_many :answers, :dependent =&gt; :destroy\n  # THis is the plularized form of sms, it's not smss\n  has_many :sms\n                                          #If someone creates a form with a blank question field at the end, this will prevent it from being rendered on teh show page\n  accepts_nested_attributes_for :answers, :allow_destroy =&gt; true\n\nend\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:22:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to run a functional test on my PollsController and keep getting this error: block in assert_valid_keys&#8217;: Unknown key: through (ArgumentError) I&#8217;m wondering if its because I have a dependent destroy on the Question model and a has_many relationship ship through it to sms. Any advice? Thanks!! Here&#8217;s the Poll model class Poll &lt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1092","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1092"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1092\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}