# Associations are not found with STI using Rails 2.3

**URL:** <https://www.ruby-forum.com/t/associations-are-not-found-with-sti-using-rails-2-3/177478>\
**Category:** Rails\
**Created:** [October 18, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/associations-are-not-found-with-sti-using-rails-2-3/177478 "2009-10-18T21:03:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbhatti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sbhatti](https://www.ruby-forum.com/u/sbhatti)\
**Post date:** [October 18, 2009, 9:03pm UTC](https://www.ruby-forum.com/t/associations-are-not-found-with-sti-using-rails-2-3/177478/1 "2009-10-18T21:03:24Z")

</div>

I have recently upgraded my Rails app to 2.3. I am using STI where I  
have class called BaseProfile that is extended by IndividualProfile. I  
have some assocations that are defined in BaseProfile but I have been  
getting errors when views reference those relationships, e.g.

undefined method `primary\_user?’ for #IndividualProfile:0x7fcb3ecea278  
RAILS\_ROOT: /home2/plexobje/rails/linktank

Application Trace | Framework Trace | Full Trace  
/home/plexobje/.gems/gems/activerecord-2.3.4/lib/active\_record/attribute\_methods.rb:255:in  
`method_missing' /home2/plexobje/rails/linktank/app/models/individual_profile.rb:32:in`latest\_event’  
/home/plexobje/.gems/gems/activerecord-2.3.4/lib/active\_record/associations/association\_proxy.rb:221:in  
`send' /home/plexobje/.gems/gems/activerecord-2.3.4/lib/active_record/associations/association_proxy.rb:221:in`method\_missing’  
/home2/plexobje/rails/linktank/app/controllers/application\_controller.rb:99:in  
`get_upcoming_rsvp' /home/plexobje/.gems/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:178:in`send’  
/home/plexobje/.gems/gems/activesupport-2.3.4/lib/active\_support/callbacks.rb:178:in  
`evaluate_method' /home/plexobje/.gems/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:166:in`call’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/filters.rb:225:in  
`call' /home/plexobje/.gems/gems/actionpack-2.3.4/lib/action_controller/filters.rb:629:in`run\_before\_filters’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/filters.rb:615:in  
`call_filters' /home/plexobje/.gems/gems/actionpack-2.3.4/lib/action_controller/filters.rb:610:in`perform\_action\_without\_benchmark’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_without_rescue' /home/plexobje/.gems/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in`ms’  
/home/plexobje/.gems/gems/activesupport-2.3.4/lib/active\_support/core\_ext/benchmark.rb:10:in  
`realtime' /home/plexobje/.gems/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in`ms’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/benchmarking.rb:68:in  
`perform_action_without_rescue' /home/plexobje/.gems/gems/actionpack-2.3.4/lib/action_controller/rescue.rb:160:in`perform\_action\_without\_flash’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/flash.rb:146:in  
`perform_action' /home/plexobje/.gems/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:in`send’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/base.rb:532:in  
`process_without_filters' /home/plexobje/.gems/gems/actionpack-2.3.4/lib/action_controller/filters.rb:606:in`process’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/base.rb:391:in  
`process' /home/plexobje/.gems/gems/actionpack-2.3.4/lib/action_controller/base.rb:386:in`call’  
/home/plexobje/.gems/gems/actionpack-2.3.4/lib/action\_controller/routing/route\_set.rb:437:in  
`call’

The primary\_user? is defined in parent class. This code used to work  
with older version of Rails. Is there a fix for this?  
Thanks.

---

<div class="post-metadata">

**Author:** ![sbhatti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sbhatti](https://www.ruby-forum.com/u/sbhatti)\
**Post date:** [October 19, 2009, 7:16pm UTC](https://www.ruby-forum.com/t/associations-are-not-found-with-sti-using-rails-2-3/177478/2 "2009-10-19T19:16:02Z")

</div>

On Oct 18, 3:03 pm, Shahzad B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have recently upgraded my Rails app to 2.3. I am using STI where I  
> have class called BaseProfile that is extended by IndividualProfile. I  
> have some assocations that are defined in BaseProfile but I have been  
> getting errors when views reference those relationships, e.g.
> 
> undefined method `primary\_user?’ for #IndividualProfile:0x7fcb3ecea278  
> RAILS\_ROOT: /home2/plexobje/rails/linktank  
> [snip]  
> The primary\_user? is defined in parent class. This code used to work  
> with older version of Rails. Is there a fix for this?  
> Thanks.

You weren’t kidding about the “older version” part, were you? 🙂 That  
method was deprecated back in 0.9.5(!!) (January 2005) and went away  
several versions later. Even the deprecation warning is gone now.

The now-long-gone deprecation message recommended that you use ==  
instead; you’ll need to check if you were passing the second argument  
(force\_reload) or not.

–Matt J.

---

<div class="post-metadata">

**Author:** ![sbhatti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sbhatti](https://www.ruby-forum.com/u/sbhatti)\
**Post date:** [October 20, 2009, 4:33am UTC](https://www.ruby-forum.com/t/associations-are-not-found-with-sti-using-rails-2-3/177478/3 "2009-10-20T04:33:45Z")

</div>

Matt J. wrote:

> On Oct 18, 3:03ï¿½pm, Shahzad B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > I have recently upgraded my Rails app to 2.3. I am using STI where I  
> > have class called BaseProfile that is extended by IndividualProfile. I  
> > have some assocations that are defined in BaseProfile but I have been  
> > getting errors when views reference those relationships, e.g.
> > 
> > undefined method `primary\_user?’ for #IndividualProfile:0x7fcb3ecea278  
> > RAILS\_ROOT: /home2/plexobje/rails/linktank  
> > [snip]  
> > The primary\_user? is defined in parent class. This code used to work  
> > with older version of Rails. Is there a fix for this?  
> > Thanks.
> 
> You weren’t kidding about the “older version” part, were you? 🙂 That  
> method was deprecated back in 0.9.5(!!) (January 2005) and went away  
> several versions later. Even the deprecation warning is gone now.
> 
> The now-long-gone deprecation message recommended that you use ==  
> instead; you’ll need to check if you were passing the second argument  
> (force\_reload) or not.
> 
> –Matt J.

As I said, primary\_user? was defined in my class and I wasn’t using  
deprecated method. However, it looks like Rails filters that method so I  
renamed it and it works now.
