active_fedora icon indicating copy to clipboard operation
active_fedora copied to clipboard

Can't Index Both AF::Base Objects AND Literals

Open tpendragon opened this issue 10 years ago • 6 comments

This is a problem introduced by #830 that I didn't notice until I'd merged it. If you have something like this...

class GenericAsset < ActiveFedora::Base
  property :set, :predicate => RDF::DC.title, :class_name => "Set"
end

and you do something like

g = GenericAsset.new
g.title = ["Test"]
g.save

it'll error with something like

Exception: NoMethodError: undefined method `uri' for "Test":String
--
 0: /Users/terrellt/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/active-triples-0.7.1/lib/active_triples/relation.rb:20:in `map'
 1: /Users/terrellt/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/active-triples-0.7.1/lib/active_triples/relation.rb:20:in `map'
 2: /Users/terrellt/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/active_fedora-1db3d1f986d5/lib/active_fedora/rdf/field_map.rb:78:in `find_values'

It's always been valid to store literals alongside URIs, and it'd just cast to the object if it could.

tpendragon avatar Jun 26 '15 17:06 tpendragon

@awead Pinging you, since this was your PR.

tpendragon avatar Jun 26 '15 17:06 tpendragon

I'd need to defer to @jcoyne on this one, as he and I worked on this refactor. I'm not sure what the value of specifying a string for your class is, as opposed to the class itself if it's supposed to be an instance of AF::Base.

awead avatar Jun 26 '15 18:06 awead

I would change ResourceBuilder to:

    class ResourceBuilder < Builder
      def find_values
        object.send(name).respond_to?(:uri)
          object.send(name).map(&:uri)
        else
          Array(object.send(name))
        end
      end
    end

awead avatar Jun 26 '15 18:06 awead

@terrellt I can't reproduce this. See https://gist.github.com/awead/9b383247c425d3d73d1d

awead avatar Jun 29 '15 15:06 awead

@terrellt can we close this?

awead avatar Oct 16 '15 13:10 awead

@tpendragon closable?

atz avatar Jun 02 '17 00:06 atz