Open lra opened 11 years ago
Graph DB servers like Neo4j Server and Rexster identify vertex and edge as separate types, but they don't necessarily provide a way for you to distinguish a Person vertex from a Comment vertex.
When modeling graphs, it's common to include a "type" property on each vertex so that you can query and filter on vertices of a specific type, and this also enables your client code to know what type of vertex was returned, if for example you executed a Gremlin query that returned vertices of mixed types.
Element is the base class for Vertex and Edge. Bulbs models use the element_type class var to specify the Vertex/Node type, and Bulbs uses the edge label to distinguish edge types. Bulbs keeps track of all your custom types by automatically adding the Model classes to the client.registry whenever you create its model proxy object. For example:
from bulbs.neo4jserver import Graph
from people import Person
g = Graph()
g.add_proxy("people", Person) # Person class is added to the registry
james = g.people.create(name="James")
When an element of certain type is returned by a query, Bulbs uses the type to automatically initialize the returned value to the appropriate model object. If no custom type is set on the returned element, Bulbs just initializes it to a generic Vertex or Edge object.
The type_var
and label_var
are configurable so you can change them if need be -- but this usually isn't necessary unless for rare cases where you already have a property called element_type
in your existing data that means something else.
Cool that makes sense.
I tried to find a place to explain this in the doc, but it seems that the doc on http://bulbflow.com/docs/ is outdated compared to what's on github. Also I can't find how to compile the docs to check the output.
If you need help updating the doc I'd be glad to. I would just need to know how you usually compile the docs locally.
Docs are getting a major overhaul for the Bulbs 0.4 release.
@espeed does the element_type work with neo4j 2+ node labels?
Hi,
I'm trying to understand what element_type and label are for in a model definition.
These seem to be the default names for the type_var of a Node and the label_var of a Relationship. And those variable seems to be used to name those elements in the graph database.
I'm willing to do a PR with a documentation update clarifying those, but can you explain what they are really for ?
Thanks !