Storing serialized data in an object in Neo4j
I just migrated my Rails app from MySql to Neo4j. I have been storing a list of user's websites as a serialized string in my DB (ex. User.websites = "www.facebook.com","www.twitter.com",etc..)
When I try to 开发者_开发技巧create or update that attribute I get the following error:
RuntimeError (Not allowed to store array with value...
What's the best way to go about storing an array or serialized data in Neo4j?
It highly depends on what you want to do later with this data. Are this websites meaningful peces of your data model? or are just logging stuff?
In case 1, so in case of being meaningful peces of your model. My recommendation is to have something like this User ---[related_to]---> Website(url:string)
In case 2, they can be just an array of strings inside the user node. As you can see in the Neo4j api documentation, you can store as properties the next set of types:
- boolean or boolean[]
- byte or byte[]
- short or short[]
- int or int[]
- long or long[]
- float or float[]
- double or double[]
- char or char[]
java.lang.String or String[]
- purbon
In addition to the discussion above, here's an example way to serialize ( http://gist.github.com/1674551 )
neo4jhelpers.rb
module Neo4j
module TypeConverters
class SerializeConverter
# serializes to sting
class << self
def convert?(type)
type == :serialize
end
def to_java(value)
return nil unless value
JSON.generate(value).to_s
end
def to_ruby(value)
return nil unless value
JSON.parse(value.to_s)
end
end
end
end
end
Neo4j::TypeConverters.converters = nil # reload converters
精彩评论