ncbo / goo

Graph Oriented Objects (GOO) for Ruby. A RDF/SPARQL based ORM.
http://ncbo.github.io/goo/
Other
15 stars 6 forks source link

Error when not using model call in class definition #31

Closed palexander closed 11 years ago

palexander commented 11 years ago

There is a problem when using goo objects without making the model call in the class definition. It happens when there is a dependent object. See code below.

class Ontology < Goo::Base::Resource
  attribute :acronym, :unique => true, :cardinality => { :max => 1, :min => 1 }
  attribute :name, :cardinality => { :max => 1, :min => 1 }
end

class Project < Goo::Base::Resource
  attribute :name, :cardinality => { :max => 1, :min => 1 }
  attribute :ontologyUsed, :instance_of => { :with => :ontology }, :cardinality => { :min => 1 }
end

p = LinkedData::Models::Project.new({
    :name => "Great Project",
    :ontologyUsed => [LinkedData::Models::Ontology.new(acronym: "SNOMED", name: "SNOMED CT")]
  })

assert_equal false, p.exist?(reload=true)
p.save
assert_equal true, p.exist?(reload=true)
p.delete
assert_equal false, p.exist?(reload=true)

The following code results in an error when running p.save: ArgumentError: Model ontology is not registered.

msalvadores commented 11 years ago

I have added the example code as test and it works. Probably one of the commits between when this was submitted and now fixed it.