lib/arrest/attributes/belongs_to.rb in arrest-0.0.9 vs lib/arrest/attributes/belongs_to.rb in arrest-0.0.11
- old
+ new
@@ -16,13 +16,15 @@
if params
field_name = params[:field_name] unless params[:field_name] == nil
class_name = params[:class_name].to_s unless params[:class_name] == nil
read_only = params[:read_only] == true
end
- attributes({field_name.to_sym => String})
add_attribute(Attribute.new(field_name.to_sym, read_only, String))
send :define_method, name do
val = self.send(field_name)
+ if val == nil || val == ""
+ return nil
+ end
begin
Arrest::Source.mod.const_get(class_name).find(val)
rescue Errors::DocumentNotFoundError => e
raise Errors::DocumentNotFoundError, "Couldnt find a #{class_name} with id #{val}"
end