Commit ba1dafd8 authored by Aurelien Campeas's avatar Aurelien Campeas
Browse files

[entities] fix cw_instantiate typo

--HG--
branch : stable
parent 040d3597444f
......@@ -252,10 +252,12 @@ class Entity(AppObject):
>>> companycls = vreg['etypes'].etype_class(('Company')
>>> personcls = vreg['etypes'].etype_class(('Person')
>>> c = companycls.cw_instantiate(req.execute, name=u'Logilab')
>>> personcls.cw_instantiate(req.execute, firstname=u'John', lastname=u'Doe',
... works_for=c)
>>> c = companycls.cw_instantiate(session.execute, name=u'Logilab')
>>> p = personcls.cw_instantiate(session.execute, firstname=u'John', lastname=u'Doe',
... works_for=c)
You can also set relation where the entity has 'object' role by
prefixing the relation by 'reverse_'.
"""
rql = 'INSERT %s X' % cls.__regid__
relations = []
......@@ -274,14 +276,14 @@ class Entity(AppObject):
if len(value) == 1:
value = iter(value).next()
else:
# prepare IN clause
del kwargs[attr]
pending_relations.append( (attr, value) )
continue
if hasattr(value, 'eid'): # non final relation
rvar = attr.upper()
# XXX safer detection of object relation
if attr.startswith('reverse_'):
relations.append('%s %s X' % (rvar, attr[len('reverse_'):]))
if role == 'object':
relations.append('%s %s X' % (rvar, attr))
else:
relations.append('X %s %s' % (attr, rvar))
restriction = '%s eid %%(%s)s' % (rvar, attr)
......
Markdown is supported
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