Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: denyago/remote_association
base: 7a38ef10e1
...
head fork: denyago/remote_association
compare: 5915e5d152
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 26, 2012
@denyago Honor primary_key class properties cc371aa
@denyago Merge branch 'master' of github.com:denyago/remote_association
Conflicts:
	lib/remote_association/has_many_remote.rb
	lib/remote_association/has_one_remote.rb
5915e5d
View
6 lib/remote_association/active_record/relation.rb
@@ -103,9 +103,10 @@ def fetch_and_join_for_has_any_remote(settings)
keys = @records.uniq.map(&:id)
remote_objects = fetch_remote_objects(settings.ar_class, keys, settings.ar_accessor)
+ join_key = klass.primary_key
@records.each do |record|
- record.send("#{settings.ar_accessor}=", remote_objects.select { |s| s.send(settings.foreign_key) == record.id })
+ record.send("#{settings.ar_accessor}=", remote_objects.select { |s| s.send(settings.foreign_key) == record.send(join_key) })
end
end
@@ -115,9 +116,10 @@ def fetch_and_join_for_belongs_to_remote(settings)
return if keys.empty?
remote_objects = fetch_remote_objects(settings.ar_class, keys, settings.ar_accessor)
+ join_key = settings.ar_class.primary_key
@records.each do |record|
- record.send("#{settings.ar_accessor}=", remote_objects.select { |s| record.send(settings.foreign_key) == s.id })
+ record.send("#{settings.ar_accessor}=", remote_objects.select { |s| record.send(settings.foreign_key) == s.send(join_key) })
end
end
View
2  lib/remote_association/belongs_to_remote.rb
@@ -48,7 +48,7 @@ def belongs_to_remote(remote_rel, options ={})
class_name: remote_rel.to_s.classify,
foreign_key: remote_rel.to_s.foreign_key,
association_type: :belongs_to_remote,
- primary_key: 'id'
+ primary_key: primary_key
}.merge(options.symbolize_keys)
add_activeresource_relation(remote_rel.to_sym, rel_options)
View
6 lib/remote_association/has_many_remote.rb
@@ -59,8 +59,9 @@ def has_many_remote(remote_rel, options ={})
# if remote_resources_loaded?
# @customers ? @customers : nil
# else
+ # join_key = self.class.primary_key
# @customers ||= Person.
- # find(:all, params: self.class.build_params_hash_for_customers(self.id))
+ # find(:all, params: self.class.build_params_hash_for_customers(self.send(join_key)))
# end
# end
#
@@ -68,8 +69,9 @@ def #{remote_rel}
if remote_resources_loaded?
@#{remote_rel} ? @#{remote_rel} : []
else
+ join_key = self.class.primary_key
@#{remote_rel} ||= #{rel_options[:class_name]}.
- find(:all, params: self.class.build_params_hash_for_#{remote_rel}(self.id))
+ find(:all, params: self.class.build_params_hash_for_#{remote_rel}(self.send(join_key)))
end
end
View
3  lib/remote_association/has_one_remote.rb
@@ -54,7 +54,8 @@ def #{remote_rel}
if remote_resources_loaded?
@#{remote_rel} ? @#{remote_rel}.first : nil
else
- @#{remote_rel} ||= #{rel_options[:class_name]}.find(:first, params: self.class.build_params_hash_for_#{remote_rel}(self.id))
+ join_key = self.class.primary_key
+ @#{remote_rel} ||= #{rel_options[:class_name]}.find(:first, params: self.class.build_params_hash_for_#{remote_rel}(self.send(join_key)))
end
end

No commit comments for this range

Something went wrong with that request. Please try again.