# Has\_one :through doesn't work in Rails 2.2.2

**URL:** <https://www.ruby-forum.com/t/has-one-through-doesnt-work-in-rails-2-2-2/156861>\
**Category:** Rails\
**Created:** [January 4, 2009, 1:16pm UTC](https://www.ruby-forum.com/t/has-one-through-doesnt-work-in-rails-2-2-2/156861 "2009-01-04T13:16:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [January 4, 2009, 1:16pm UTC](https://www.ruby-forum.com/t/has-one-through-doesnt-work-in-rails-2-2-2/156861/1 "2009-01-04T13:16:39Z")

</div>

I followed the steps in the following link literally in a new Rails  
2.2.2 project  
[http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-one-through](http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-one-through)

Then I ran it in script/console, getting these error (actually I got  
same error in another big rails project before I read that link):

NoMethodError: undefined method `update_attributes' for #<Class: 0xb7069980> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/base.rb:1833:in `method\_missing’  
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/  
active\_record/associations/association\_collection.rb:370:in `send' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_collection.rb:370:in `method\_missing’  
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/  
active\_record/base.rb:2003:in `with_scope' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_proxy.rb:202:in `send’  
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/  
active\_record/associations/association\_proxy.rb:202:in `with_scope' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_collection.rb:366:in `method\_missing’  
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/  
active\_record/associations/has\_one\_through\_association.rb:11:in  
`create_through_record' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations.rb:1273:in `magazine=’  
from (irb):4

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [January 5, 2009, 7:50am UTC](https://www.ruby-forum.com/t/has-one-through-doesnt-work-in-rails-2-2-2/156861/2 "2009-01-05T07:50:14Z")

</div>

I simply copied the code in that link, and in the associated table there  
were only needed fields to establish the relations.

Regards,  
æž—ä¸­é¹

On Sun, Jan 4, 2009 at 8:19 PM, Frederick C.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [January 5, 2009, 4:03pm UTC](https://www.ruby-forum.com/t/has-one-through-doesnt-work-in-rails-2-2-2/156861/3 "2009-01-05T16:03:59Z")

</div>

Maybe your defined rails version in environment.rb is not 2.2.2?

---

<div class="post-metadata">

**Author:** ![clive](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f08c70/32.png) [@clive](https://www.ruby-forum.com/u/clive)\
**Post date:** [January 16, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/has-one-through-doesnt-work-in-rails-2-2-2/156861/4 "2009-01-16T16:34:40Z")

</div>

I was having the same issue as Clive trying to test the referenced  
example  
I was able to get some functionality by using :has\_one subscription  
rather than :has\_many.

I do have a question though.

I can set the through association like this

user=User.create(:name=\>“Bob”)  
m=Magazine.create(:name=\>‘test’)  
user.magazine=m  
then user.subscription will = #\<Subscription id: 1, user\_id: 1,  
magazine\_id: 1…\>

However,  
using user.update\_attributes(:magazine=\>m)  
the return is true, but there is no association created. Subscription  
remains nil.

Am I wrong in assuming that I should be able to do this?
