05-19-2020, 03:24 PM
Hi, Diego.
For my own needs, I have achieved the right solution.
But i did not tested it with DropElementAction and DropElementWdg, as i don't use it for asset_to_assets relations, i just use scripting and api.
I ended up with this schema entries:
<connect from="dolly3d/assets" to="dolly3d/assets" instance_type="dolly3d/assets_in_assets" relationship="instance"/>
<connect from="dolly3d/assets_in_assets" to="dolly3d/assets" relationship="code" from_col="parent_assets_code" to_col="code" path="child" type="many_to_many"/>
<connect from="dolly3d/assets_in_assets" to="dolly3d/assets" relationship="code" from_col="child_assets_code" to_col="code" path="parent" type="many_to_many"/>
<connect from="dolly3d/assets_in_assets" to="dolly3d/assets" relationship="code" from_col="parent_assets_code" to_col="code" type="many_to_many"/>
And script to add and remove relationship:
When i query my assets i also use "path", for example @SOBJECT(child:dolly3d/assets_in_assets['parent_assets_code', 'ASSETS00334'].parent:dolly3d/assets)
For my own needs, I have achieved the right solution.
But i did not tested it with DropElementAction and DropElementWdg, as i don't use it for asset_to_assets relations, i just use scripting and api.
I ended up with this schema entries:
<connect from="dolly3d/assets" to="dolly3d/assets" instance_type="dolly3d/assets_in_assets" relationship="instance"/>
<connect from="dolly3d/assets_in_assets" to="dolly3d/assets" relationship="code" from_col="parent_assets_code" to_col="code" path="child" type="many_to_many"/>
<connect from="dolly3d/assets_in_assets" to="dolly3d/assets" relationship="code" from_col="child_assets_code" to_col="code" path="parent" type="many_to_many"/>
<connect from="dolly3d/assets_in_assets" to="dolly3d/assets" relationship="code" from_col="parent_assets_code" to_col="code" type="many_to_many"/>
And script to add and remove relationship:
Code:
def edit_multiple_instance_sobjects(project_code, insert_search_keys=[], exclude_search_keys=[], parent_key=None, instance_type=None, path=None):
from pyasm.search import SearchType, Search
server.set_project(project_code)
def remove_instance(to_sobject, from_sobject, instance_type):
from_expression = '@SOBJECT(child:{0})'.format(instance_type)
to_expression = '@SOBJECT(parent:{0})'.format(instance_type)
from_instances = Search.eval(from_expression, from_sobject)
to_instances = Search.eval(to_expression, to_sobject)
for from_instance in from_instances:
from_search_key = from_instance.get_search_key()
for to_instance in to_instances:
to_search_key = to_instance.get_search_key()
if from_search_key == to_search_key:
to_instance.delete()
for search_key in insert_search_keys:
child_search_type, child_code = server.split_search_key(search_key)
parent_search_type, parent_code = server.split_search_key(parent_key)
dst_sobject= server.query(parent_search_type, [('code', parent_code)], return_sobjects=True)[0]
src_sobject = server.query(child_search_type, [('code', child_code)], return_sobjects=True)[0]
instance = SearchType.create(instance_type)
instance.add_related_connection(src_sobject, dst_sobject, src_path=path)
instance.commit()
for search_key in exclude_search_keys:
child_search_type, child_code = server.split_search_key(search_key)
parent_search_type, parent_code = server.split_search_key(parent_key)
child_sobject = server.query(child_search_type, [('code', child_code)], return_sobjects=True)[0]
parent_sobject = server.query(parent_search_type, [('code', parent_code)], return_sobjects=True)[0]
if path:
remove_instance(child_sobject, parent_sobject, instance_type)
else:
child_sobject.remove_instance(parent_sobject)
When i query my assets i also use "path", for example @SOBJECT(child:dolly3d/assets_in_assets['parent_assets_code', 'ASSETS00334'].parent:dolly3d/assets)