lib/active_remote/association.rb in active_remote-1.3.0 vs lib/active_remote/association.rb in active_remote-1.3.1

- old
+ new

@@ -37,11 +37,13 @@ # end # end # def belongs_to(belongs_to_klass, options={}) perform_association( belongs_to_klass, options ) do |klass, obj| - klass.search(:guid => obj.read_attribute(:"#{belongs_to_klass}_guid")).first + foreign_key = options.fetch(:foreign_key) { :"#{belongs_to_klass}_guid" } + association_guid = obj.read_attribute(foreign_key) + klass.search(:guid => association_guid).first end end # Create a `has_many` association for a given remote resource. # Specify one or more associations to define. The constantized @@ -73,11 +75,12 @@ # end # end # def has_many(has_many_class, options={}) perform_association( has_many_class, options ) do |klass, obj| - klass.search(:"#{obj.class.name.demodulize.underscore}_guid" => obj.guid) + foreign_key = options.fetch(:foreign_key) { :"#{obj.class.name.demodulize.underscore}_guid" } + klass.search(foreign_key => obj.guid) end end # Create a `has_one` association for a given remote resource. # Specify one or more associations to define. The constantized @@ -108,10 +111,11 @@ # end # end # def has_one(has_one_klass, options={}) perform_association( has_one_klass, options ) do |klass, obj| - klass.search(:"#{obj.class.name.demodulize.underscore}_guid" => obj.guid).first + foreign_key = options.fetch(:foreign_key) { :"#{obj.class.name.demodulize.underscore}_guid" } + klass.search(foreign_key => obj.guid).first end end private