neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

ActiveRel type checks need to respect module config #1200

Open subvertallchris opened 8 years ago

subvertallchris commented 8 years ago
# Given
Neo4j::Config[:association_model_namespace] = 'Graph'
Neo4j::Config[:module_handling] = :demodulize

module Graph
  class MyRel
    include Neo4j::ActiveRel
    # Venue is namespaced as Graph::Venue to avoid conflicts with ::Venue
    from_class :Venue
    # etc
  end
end

# This should not happen

MyRel.create(graph_venue, graph_event)
NoMethodError: undefined method `mapped_label_name' for #<Class:0x007fadd3248348>

There's also an issue with rel_class in associations. I ended up having less time than I thought so couldn't get to a fix, will do it soon.

cheerfulstoic commented 8 years ago

I was discussing this with @leviwilson the other day. I think that the default behavior for ActiveRel should be to demodulize and you should need to configure to include the module. After all, if you have Graph::MyRel and Foo::MyRel, it doesn't matter if you have multiple relationships that have the same type of MY_REL (or my_rel, depending on your settings). Also it's just weird if you were to do GRAPH_MY_REL / FOO_MY_REL by default. The class name is almost always what's describing the relationship type.

@leviwilson ran into this originally because it was trying to do Graph::MyRel as the relationship type without using backticks and giving an error (perhaps that's what you got as well).