This project is archived and is in readonly mode.

#5966 ✓stale

Association proxy does not forward missing methods to the actual instance

Reported by wereHamster | November 13th, 2010 @ 01:00 PM

Given a simple association:

class City < ActiveRecord::Base
  belongs_to :country

class Country < ActiveRecord::Base
  def method_missing(method, *args)
    p "method #{method} not found on #{self}"

I am able to create objects of type Country and missing methods are correctly forwarded to my method_missing:

country =
# prints "method non_existing_method not found on #<Country..>"

However when I create an City object and assign the country object, it stops working:

city = => country)
# raises NoMethodError

I can work around this by using try:

But that is ugly. And not intuitive.

Comments and changes to this ticket

  • wereHamster

    wereHamster November 13th, 2010 @ 01:20 PM

    Just when I posted the ticket I figured out how the association proxies work. How does this patch look?

  • wereHamster
  • Neeraj Singh

    Neeraj Singh November 13th, 2010 @ 05:50 PM

    • Importance changed from “” to “Low”

    Patch looks good. I think you should attach a test too.

  • Cesario

    Cesario November 13th, 2010 @ 08:21 PM

    • Tag set to active record, 3.0


    Your commit makes the tests go read.

    The problem with defining method with method_missing is that @target.respond_to?(method) (in the association proxy piece of code you mention) will always returns false.

  • rails

    rails February 14th, 2011 @ 12:00 AM

    • State changed from “new” to “open”
    • Tag changed from active record, 3.0 to active record, 30

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails February 14th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”
  • af001

    af001 May 5th, 2011 @ 02:55 AM


Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>