- From: Ben Lavender <blavender@gmail.com>
- Date: Fri, 24 Sep 2010 12:56:29 -0500
- To: Dominic Sisneros <dsisnero@gmail.com>
- Cc: public-rdf-ruby@w3.org
Sorry, I can't reproduce this directly from this code; you're missing an assigned_to property declaration on Person, and the declaration of the vocabulary. The only way I can produce this error is if you declare Person after Project, and add the following property to Person: property :assigned_to, :predicate => PM.assignedTo, :type => Project (declaring Person first, this will get you an 'unknown constant' error instead of the error you show). So your problem is not self-referencing. Try replacing any constants you have for referencing relation classes with symbols. A script demonstrating a self-referencing project is below. HTH, Ben #!/usr/bin/env ruby1.9 require 'spira' class PM < RDF::Vocabulary('http://example.org/pm'); end Spira.add_repository(:default, RDF::Repository.new) class Project include Spira::Resource type PM['Project'] base_uri "http://example.org/example/projects" property :name, :predicate => PM.test_name, :type => String property :parent, :predicate => PM.subProjectOf, :type =>:Project has_many :children, :predicate => PM.subProject, :type =>:Project end project = Project.new project.name = 'A new project' project.save! project2 = Project.new project2.name = 'a subproject' project2.parent = project project2.save! p Spira.repository(:default).size On Fri, Sep 24, 2010 at 3:32 AM, Dominic Sisneros <dsisnero@gmail.com> wrote: > When I try to self reference a type I get the following error: > > .0.8/lib/spira/resource/dsl.rb:243:in `add_accessors': Unrecognized type: > Project (TypeError) > > A code example is as below > > class Person > > include Spira::Resource > > base_uri "http://example.org/example/people" > > property :name, :predicate => FOAF.name, :type => String > property :age, :predicate => FOAF.age, :type => Integer > > end > > class Project > include Spira::Resource > > type PM['Project'] > > base_uri "http://example.org/example/projects" > > property :name, :predicate => PM.name, :type => String > > > property :parent, :predicate => PM.subProjectOf, :type =>:project > has_many :children, :predicate => PM.subProject, :type =>:project > > end > > bob = RDF::URI("http://example.org/people/bob").as(Person) > bob.age = 15 > bob.name = "Bob Smith" > bob.save! > > project = Project.new > project.name = 'A new project' > project.assigned_to = bob > project.save! > > project2 = Project.new > project2.name = 'a subproject' > project2.parent = project > project2.save! > > Is this possible and how would I do it? > > thanks >
Received on Friday, 24 September 2010 17:57:22 UTC