Associations failing
tgmerritt opened this issue · comments
Trace shows:
comma (3.1.0) lib/comma/extractors.rb:72:in `get_association_class'
comma (3.1.0) lib/comma/extractors.rb:55:in `block in method_missing'
Code is:
def get_association_class(model_class, association)
model_class.respond_to?(:reflect_on_association) ?
model_class.reflect_on_association(arg).klass : nil
end
end
In my job.rb model I have:
belongs_to :customer
And then in Comma:
comma do
customer :first_name
end
And the error for Rails is :
undefined method `klass' for nil:NilClass
I can't understand why it doesn't recognize my association.
Using comma 3.1.0, Ruby-2.0, Rails 3.2.13
Thank you for your bug report. Here is a patch to fix this issue.
diff --git a/lib/comma/extractors.rb b/lib/comma/extractors.rb
index 81ee23a..63fe5e2 100644
--- a/lib/comma/extractors.rb
+++ b/lib/comma/extractors.rb
@@ -69,7 +69,7 @@ module Comma
def get_association_class(model_class, association)
model_class.respond_to?(:reflect_on_association) ?
- model_class.reflect_on_association(arg).klass : nil
+ model_class.reflect_on_association(association).klass : nil
end
end
I will write tests and submit PR later.