Calling save in example code throws exception
Closed this issue · 4 comments
I can't seem to get any of the examples to work fully; everything is fine until I try to call save!
on an object, which gives me
NoMethodError: undefined method `has_subject?' for nil:NilClass
from /home/wstrinz/.rvm/gems/ruby-1.9.3-p429/gems/spira-0.5.0/lib/spira/persistence.rb:285:in `new_record?'
If I call bob.subject
it returns the expected uri, but maybe this is something other than the subject
that the new_record?
method is looking for?
It seems to be the same for the Person, Artist, and CD objects in the examples in the readme. I dug into the code a bit, but I couldn't figure out what was going on since 'subject' seems to be some kind of reserved word and I'm not quite sure how it's supposed to work. Is this just happening because I don't actually have anywhere to save the resource to? I thought it would just stay in memory, but if not maybe a note could be added about this to the examples? I'd be happy to submit a PR if that's the case :)
it also happened to me. its about namespace if you are using.
Here is a sample.
property :awarded_with, :predicate => Semantic::OntDakick.awarded_with, :type => "Knowledgebase::Award"
if your models exist under a namespace you should declare properties as above.
I'm not sure what namespace the examples in the readme are in, I tried to make sure I specified them all explicitly in this simple class:
class Person < Spira::Base
configure :base_uri => "http://example.org/example/people"
property :age, :predicate => RDF::FOAF.age, :type => Spira::Types::Int
end
but when I try to use it:
bob = RDF::URI("http://example.org/people/bob").as(Person)
bob.age = 3
bob.save
I get the NoMethodError exception.
I'm pretty sure this is happening because I don't have a repository configured, since the exception looks like it's happening when I call has_subject?
on the repository object for the resource, which is nil. I'll go ahead and close my issue, but maybe in the future a note about this could be added to the readme, since the error message is pretty uninformative about what's causing the problem. Thanks for your response though!
This pull request takes care of this issue. Thanks for reporting.
I'd appreciate if any other member of @ruby-rdf team reviewed it and merged in. Thank you!
Cool, thanks for adding that!