Can Relationships have date properties?

7 views
Skip to first unread message

Max De Marzi Jr.

unread,
Nov 19, 2009, 5:10:23 PM11/19/09
to neo...@googlegroups.com
Hello,

I have a model:

class Student
  include Neo4j::RelationshipMixin
  property :from , :type => Date
  property :to , :type => Date
  property :diploma
end

but I am getting this error message:
typeDate is not a string
/home/max/software/jruby-1.4.0RC1/lib/ruby/gems/1.8/gems/neo4j-0.3.2/lib/neo4j/mixins/relationship_mixin.rb:221:in `define_method'
/home/max/software/jruby-1.4.0RC1/lib/ruby/gems/1.8/gems/neo4j-0.3.2/lib/neo4j/mixins/relationship_mixin.rb:221:in `property'
/home/max/software/jruby-1.4.0RC1/lib/ruby/gems/1.8/gems/neo4j-0.3.2/lib/neo4j/mixins/relationship_mixin.rb:220:in `each'
/home/max/software/jruby-1.4.0RC1/lib/ruby/gems/1.8/gems/neo4j-0.3.2/lib/neo4j/mixins/relationship_mixin.rb:220:in `property'
/home/max/websites/alpha.archety.pe/app/models/student.rb:3
Not sure if this is a bug, a typo or if its not allowed...
Thanks,
Max

Craig Taverner

unread,
Nov 19, 2009, 8:08:30 PM11/19/09
to neo...@googlegroups.com
I believe only primitives and String (and arrays of these) can be stored as described at:
  http://api.neo4j.org/current/org/neo4j/api/core/PropertyContainer.html

You could convert the date to a byte[] using serialization, or to a String and parse it later. But a much simpler method is to get the long time value and save that.

But in neo4j.rb, I imagine it would be easy to wrap and hide that intelligence?

--

You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To post to this group, send email to neo...@googlegroups.com.
To unsubscribe from this group, send email to neo4jrb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/neo4jrb?hl=.

Andreas Ronge

unread,
Nov 20, 2009, 2:59:44 AM11/20/09
to neo...@googlegroups.com
Hi

Yes it only works for the NodeMixin.
I have created a ticket for this.
http://neo4j.lighthouseapp.com/projects/15548-neo4j/tickets/91-serialization-on-relationship-property

It's would be rather simple to implement it since we can reuse the
code from the NodeMixin.
Maybe you can fork my GitHub project and implement it yourself ?

Cheers
Andreas



On Fri, Nov 20, 2009 at 2:08 AM, Craig Taverner <cr...@amanzi.com> wrote:
> I believe only primitives and String (and arrays of these) can be stored as
> described at:
>   http://api.neo4j.org/current/org/neo4j/api/core/PropertyContainer.html
>
> You could convert the date to a byte[] using serialization, or to a String
> and parse it later. But a much simpler methoed is to get the long time value

Max De Marzi Jr.

unread,
Nov 20, 2009, 12:23:10 PM11/20/09
to neo...@googlegroups.com
Is this the right way to go or should we really look into mimicking the api and going with a property mixin that handles it for both nodes and relationships?  

I bring this up because relationships don't have the indexing capabilities at this point, and it might make sense to add that as well.

Max De Marzi Jr.

unread,
Nov 20, 2009, 12:35:28 PM11/20/09
to neo...@googlegroups.com
>>I bring this up because relationships don't have the indexing capabilities at this point, and it might make sense to add that as well.

This is not right is it... we can index relationships from the start and end nodes... so maybe it isn't needed at all.

Andreas Ronge

unread,
Nov 20, 2009, 1:03:16 PM11/20/09
to neo...@googlegroups.com
Yes, why not having indexing on relationships as well ?
That will be another lighthouse ticket.
Yes, one can find the relationship from a node using lucene.
Btw, it feels a bit strange to model a student as a relationship
instead of as a node (which support lucene queries).

Cheers
Andreas

Max De Marzi Jr.

unread,
Nov 20, 2009, 2:16:24 PM11/20/09
to neo...@googlegroups.com
>>Btw, it feels a bit strange to model a student as a relationship
instead of as a node (which support lucene queries).

Well I was thinking  Person -> Student -> School, and also have Person -> Employee -> School.

Also speaking of modeling, how about handling instances?

Let's say I want to have "Calculus 1" as general class (so I can find all students that took "Calculus 1")... but I also want to represent an instance of the class like "Calculus 1 Spring 2010 MWF 3:30PM" so I can find which students took this class and I want to be able to know which "Calculus 1" classes are available, etc.  

What would be the best way to model it?  The class is a node and the instance is a node, and the Person node all cross linked?

Andreas Ronge

unread,
Nov 20, 2009, 3:37:45 PM11/20/09
to neo...@googlegroups.com
Well, you can use the reindexer extension - it keeps a reference from
the IndexerNode to all instances.
So if you have a Calculus1 class you can do:

Calculus1.all.nodes which will find all instances like "Calculus 1
Spring 2010 MWF 3:30PM"

Or you can also use inheritance

class Course
include Neo4j::NodeMixin
property :name
index :name
end

class Calculus < Course
end

Course.find("Spring 2010 ...")
This works since all subclasses have the same lucene index.
And you can also do
Calculus.all.nodes # to only find Calculus nodes.

But maybe it is better you create your own node mapping - Courses as
Nodes an Course instanses as nodes as you suggested.
It gives you more freedom.

E.g.
Student -> CourseParticipant -> CourseInstance -> Course

Then you have to traverse from the Student node to the course node to
find out which course a student has taken part of.
(The CourseInstance only contains data, like time and the location
where the course is given).
It is not always obvious what to use: a relationship or a node.
In the example above the CourseParticipant could be modelled as a
relationship since it will not have any relationships related to it,
or will it ?
Maybe you should also have some timeline nodes, like a node for each
academic term etc...

Cheers

/Andreas

Rick Otten

unread,
Nov 20, 2009, 3:58:41 PM11/20/09
to neo...@googlegroups.com
> It is not always obvious what to use: a relationship or a node.

Ah, that brings back memories from graph theory classes many years ago...

I believe in many types of graphs you can swap them. (ie, make all your
relationships into nodes, and all your nodes into relationships and your
resultant graph will be equivalent to the one you started with.)

I'm going to have to dig out my graph theory texts to remember the details
though.

Thanks for the memories!



--
Rick Otten
rot...@windfish.net
http://www.cloudnavigator.com
O=='=+


Reply all
Reply to author
Forward
0 new messages