我在玩rails console
Neo4j 并尝试创建一个像这样的模型类:
Object.const_set("TestNode", Class.new(super_class=Neo4j::Rails::Model))
node = TestNode.new
如果我然后尝试保存实例,node.save
我会收到一堆错误:
node.save
NoMethodError: undefined method `each' for nil:NilClass
from /Users/oskbor/.rvm/gems/jruby-1.6.7.2/gems/neo4j-2.0.0-java/lib/neo4j/rails/attributes.rb:57:in `init_on_create'
from /Users/oskbor/.rvm/gems/jruby-1.6.7.2/gems/neo4j-2.0.0-java/lib/neo4j/rails/node_persistance.rb:16:in `create'
from /Users/oskbor/.rvm/gems/jruby-1.6.7.2/gems/neo4j-2.0.0-java/lib/neo4j/rails/callbacks.rb:39:in `create_with_callbacks'
from /Users/oskbor/.rvm/gems/jruby-1.6.7.2/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:417:in `_run__1980184148__create__1722973119__callbacks'
from org/jruby/RubyKernel.java:2076:in `send'
...
如果我像往常一样创建 TestNode 类,一切正常:
class TestNode < Neo4j::Rails::Model
end
第一种创建模型类TestNode的方法有什么问题?
我的目标是能够使用元编程动态创建新模型,然后能够将实例持久化到 neo4j 数据库。