Commit e8ea259a authored by davebshow's avatar davebshow
Browse files

property mapping is now direct

parent 2f3082d4
......@@ -287,13 +287,14 @@ Or, simply use the property :py:attr:`g<goblin.session.Session.g>`::
>>> session.g.V().hasLabel('person')...
However, when writing the traversals, it is important to note that property
names are not mapped directly from the OGM. Instead, they typically take the format:
`element_class_name__property_name`. To avoid mistakes, the mapped property names
are available as class attributes::
In general property names are not mapped directly from the OGM to the database.
However, by passing the `db_name` kwarg to a property definition, the user has
the ability to override this behavior. To avoid mistakes in the case of custom
database property names, it is encouraged to access the mapped property names
as class attributes::
>>> Person.name
'person__name'
'name'
So, to write a traversal::
......
......@@ -204,7 +204,7 @@ class Mapping:
if prop.db_name:
db_name = prop.db_name
else:
db_name = '{}__{}'.format(self._label, name)
db_name = name
if hasattr(prop, '__mapping__'):
if not self._element_type == 'vertex':
raise exception.MappingError(
......
......@@ -22,22 +22,22 @@ from goblin import exception, properties
def test_property_mapping(person, lives_in):
db_name, data_type = person.__mapping__._ogm_properties['name']
assert db_name == 'person__name'
assert db_name == 'name'
assert isinstance(data_type, properties.String)
db_name, data_type = person.__mapping__._ogm_properties['age']
assert db_name == 'custom__person__age'
assert isinstance(data_type, properties.Integer)
db_name, data_type = lives_in.__mapping__._ogm_properties['notes']
assert db_name == 'lives_in__notes'
assert db_name == 'notes'
assert isinstance(data_type, properties.String)
ogm_name, data_type = person.__mapping__._db_properties['person__name']
ogm_name, data_type = person.__mapping__._db_properties['name']
assert ogm_name == 'name'
assert isinstance(data_type, properties.String)
ogm_name, data_type = person.__mapping__._db_properties['custom__person__age']
assert ogm_name == 'age'
assert isinstance(data_type, properties.Integer)
ogm_name, data_type = lives_in.__mapping__._db_properties['lives_in__notes']
ogm_name, data_type = lives_in.__mapping__._db_properties['notes']
assert ogm_name == 'notes'
assert isinstance(data_type, properties.String)
......@@ -46,11 +46,11 @@ def test_metaprop_mapping(place):
place.historical_name = ['Iowa City']
db_name, data_type = place.historical_name(
'Iowa City').__mapping__._ogm_properties['notes']
assert db_name == 'historical_name__notes'
assert db_name == 'notes'
assert isinstance(data_type, properties.String)
db_name, data_type = place.historical_name(
'Iowa City').__mapping__._ogm_properties['year']
assert db_name == 'historical_name__year'
assert db_name == 'year'
assert isinstance(data_type, properties.Integer)
......@@ -66,11 +66,11 @@ def test_mapper_func(place, knows):
def test_getattr_getdbname(person, lives_in):
db_name = person.__mapping__.name
assert db_name == 'person__name'
assert db_name == 'name'
db_name = person.__mapping__.age
assert db_name == 'custom__person__age'
db_name = lives_in.__mapping__.notes
assert db_name == 'lives_in__notes'
assert db_name == 'notes'
def test_getattr_doesnt_exist(person):
......
......@@ -20,6 +20,6 @@ from goblin.traversal import bindprop
def test_bindprop(person_class):
db_val, (binding, val) = bindprop(person_class, 'name', 'dave', binding='n1')
assert db_val == 'person__name'
assert db_val == 'name'
assert binding == 'n1'
assert val == 'dave'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment