This project is archived and is in readonly mode.
NoMethodError in AssociationProxy#method_missing isn't helpful
-
Repository
- State changed from new to resolved
(from [566a3dce6753eb71554d54e8883204e4868aa393]) Make NoMethodError message more descriptive when an undefined message has been sent to an association [#1515 NoMethodError in AssociationProxy#method_missing isn't helpful state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
Murat Demirten
Raising NoMethodError directly in AssociationProxy's method_missing call is not a good idea. If the target object has its own method_missing call to implement some functionalities, it never called when it used in an association.
-
Roman Shterenzon
Perhaps it's better just to call the superclass?
@@ -206,7 +209,7 @@ module ActiveRecord # Forwards any missing method call to the \target. def method_missing(method, *args) if load_target - raise NoMethodError unless @target.respond_to?(method) + super unless @target.respond_to?(method) -
Steven Soroka
I don't think this was resolved correctly. association proxies should pass the method call on to the target so that the target can deal with it in its own method_missing, otherwise you're crippling a lot of meta-programming on AR objects
-
Steven Soroka
Perhaps the target could be sent the method inside a begin..rescue block that catches a NoMethodError and gives a more descriptive error, that way the AR object still has a chance to respond.
-
Steven Soroka
I have a better solution, which I've provided with a patch in #2378 AssociationProxy#method_missing masks method_missing in models
