lib/haveapi/client/resource_instance.rb in haveapi-client-0.5.3 vs lib/haveapi/client/resource_instance.rb in haveapi-client-0.5.4
- old
+ new
@@ -82,10 +82,11 @@
@params = @response.response
setup_from_clone(@resource)
define_attributes
+ @prepared_args = @response.meta[:url_params]
@resolved = true
self
end
# Return Response object which created this instance.
@@ -112,10 +113,25 @@
# id reader
ensure_method(:"#{name}_id") { @params[name][ param[:value_id].to_sym ] }
# id writer
- ensure_method(:"#{name}_id=") { |id| @params[name][ param[:value_id].to_sym ] = id }
+ ensure_method(:"#{name}_id=") do |id|
+ @params[name][ param[:value_id].to_sym ] = id
+
+ @resource_instances[name] = find_association(
+ param,
+ {
+ param[:value_id] => id,
+ :_meta => {
+ resolved: false,
+ # TODO: this will not work for nested resources, as they have
+ # multiple IDs
+ url_params: [id],
+ },
+ }
+ )
+ end
# value reader
ensure_method(name) do
@resource_instances[name] && @resource_instances[name].resolve
end