Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- ActiveResource, only constantize the resource class

  when is used it.
  • Loading branch information...
commit 47caf7e4676ec633a7a8f9a4db33892b5d539666 1 parent 7ab2337
@gramos authored
View
12 activeresource/lib/active_resource/associations.rb
@@ -24,7 +24,7 @@ def options(association, resource)
case association
when :belongs_to
- o[:association_col] = "#{o[:klass].to_s.underscore}_id".to_sym
+ o[:association_col] = "#{o[:klass].constantize.to_s.underscore}_id".to_sym
when :has_one
o[:association_col] = "#{o[:host_klass].to_s.underscore}_id".to_sym
end
@@ -34,9 +34,7 @@ def options(association, resource)
def klass_for(association, resource)
resource = resource.to_s
resource = resource.singularize if association == :has_many
-
- # FIXME constantize only when use it
- resource.camelize.constantize
+ resource.camelize
end
#######################################################################
@@ -52,7 +50,7 @@ def has_one(resource, opts = {})
#----------------------------------------------------------------------#
define_method(resource) do
set_resource_instance_variable(resource) do
- o[:klass].find(:first, :params => { o[:association_col] => id })
+ o[:klass].constantize.find(:first, :params => { o[:association_col] => id })
end
end
@@ -84,7 +82,7 @@ def belongs_to(resource, opts = {})
define_method(resource) do
association_col = send o[:association_col]
return nil if association_col.nil?
- set_resource_instance_variable(resource){ o[:klass].find(association_col) }
+ set_resource_instance_variable(resource){ o[:klass].constantize.find(association_col) }
end
#----------------------------------------------------------------------#
@@ -112,7 +110,7 @@ def has_many(resource, opts = {})
#----------------------------------------------------------------------#
define_method(resource) do
set_resource_instance_variable(resource) do
- o[:klass].find(:all, :params => { o[:association_col] => id })
+ o[:klass].constantize.find(:all, :params => { o[:association_col] => id })
end
end
end
View
7 activeresource/test/cases/associations_test.rb
@@ -1,10 +1,6 @@
require 'abstract_unit'
require "fixtures/project"
-class Milestone < ActiveResource::Base
- self.site = "http://37s.sunrise.i:3000"
-end
-
class ProjectManager < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
belongs_to :project
@@ -16,6 +12,9 @@ class Project < ActiveResource::Base
has_many :milestones
end
+class Milestone < ActiveResource::Base
+ self.site = "http://37s.sunrise.i:3000"
+end
@project = { :id => 1, :name => "Rails"}
@other_project = { :id => 2, :name => "Ruby"}
Please sign in to comment.
Something went wrong with that request. Please try again.