self to self relationship - Printable Version +- TACTIC Open Source (http://forum.southpawtech.com) +-- Forum: TACTIC Open Source (http://forum.southpawtech.com/forumdisplay.php?fid=3) +--- Forum: TACTIC Discussion (http://forum.southpawtech.com/forumdisplay.php?fid=4) +--- Thread: self to self relationship (/showthread.php?tid=29) |
RE: self to self relationship - listy - 02-06-2020 It is returning me same error: Fault: <Fault 1: 'Search type [testovy/asset_in_asset] is not related to search_type [testovy/asset]'> I also tryed add_relationship_filter method - it is returning me self object. If i pass here "ASSET00002" sobject it just returns "ASSET00002" sobject back. And there is path argument, which i think have no impact File "D:/TACTIC45/tactic-4.5/src\pyasm\search\search.py", line 1048, in add_relationship_search_filter raise SearchException("Search type [%s] is not related to search_type [%s]" % ( search_type, related_type) ) Error: Search type [testovy/asset_in_asset] is not related to search_type [testovy/asset] RE: self to self relationship - remkonoteboom - 02-06-2020 Ultimately, all of this uses the schema. Try this script: project_code = "testovy" schema = Schema.get(project_code=project_code) xml = schema.get_xml() print(xml.to_string()) print() print(schema.get_relationship_attrs("testovy/asset", "testovy/asset_in_asset")) The first print will print out the schema xml that it is actually using. The second is the one that pulls all the attributes. RE: self to self relationship - listy - 02-06-2020 This is the result: <schema> <search_type name="default/model" xpos="508" ypos="266"/> <search_type name="default/music" xpos="927" ypos="417"/> <search_type name="default/sound" xpos="528" ypos="405"/> <search_type name="default/texture" xpos="932" ypos="274"/> <search_type name="testovy/asset" xpos="494" ypos="110"/> <search_type name="testovy/asset_in_asset" xpos="696" ypos="136"/> <search_type name="testovy/episode" xpos="100" ypos="100"/> <search_type name="testovy/episode_in_asset" xpos="297" ypos="105"/> <search_type name="testovy/repo_sync_presets" xpos="1450" ypos="550"/> <search_type name="testovy/sound_in_music" xpos="728" ypos="411"/> <search_type name="testovy/texture_in_model" xpos="720" ypos="270"/> <connect from="testovy/episode_in_asset" to="testovy/episode" relationship="code"/> <connect from="testovy/episode_in_asset" to="testovy/asset" relationship="code"/> <connect from="testovy/sound_in_music" to="default/sound" relationship="code"/> <connect from="testovy/sound_in_music" to="default/music" relationship="code"/> <connect from="testovy/texture_in_model" to="default/texture" relationship="code"/> <connect from="testovy/texture_in_model" to="default/model" relationship="code"/> <connect from="testovy/asset" to="testovy/asset" instance_type="testovy/asset_in_asset" relationship="instance"/> <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="parent_asset_code" to_col="code" path="parent" type="many_to_many"/> <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="child_asset_code" to_col="code" path="child" type="many_to_many"/> </schema> {} To check print(schema.get_relationship_attrs("testovy/asset", "testovy/episode_in_asset")): {'to': 'testovy/asset', 'from_col': u'asset_code', 'from': 'testovy/episode_in_asset', 'to_col': 'code', 'relationship': 'code'} And print(schema.get_relationship_attrs("testovy/asset", "testovy/asset")): {'from': 'testovy/asset', 'relationship': 'instance', 'instance_type': 'testovy/asset_in_asset', 'to': 'testovy/asset', 'from_col': 'code', 'to_col': 'code'} RE: self to self relationship - remkonoteboom - 02-06-2020 I think I found it ... for some reason, the function that is looking for relationships skips over all of the items that have a path attribute when there is no path specified in the function. That is why episode_in_asset is working. I think it is trying to find an item with no path. Adding an entry with no path makes it work: <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="parent_asset_code" to_col="code" type="many_to_many"/> Does this work? RE: self to self relationship - listy - 02-06-2020 I have added this to schema an run this code: from pyasm.search import Search server.set_project('testovy') search_key = 'testovy/asset?project=testovy&code=ASSET00002' search_type, search_code = server.split_search_key(search_key) search = Search(search_type) sobject = search.get_by_search_key(search_key) related_sobjects = sobject.get_related_sobjects('testovy/asset_in_asset', path='child') And this is works fine. Now i have duplicates in schema: " <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="parent_asset_code" to_col="code" path="parent" type="many_to_many"/> <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="child_asset_code" to_col="code" path="child" type="many_to_many"/> <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="parent_asset_code" to_col="code" type="many_to_many"/> <connect from="testovy/asset_in_asset" to="testovy/asset" relationship="code" from_col="child_asset_code" to_col="code" type="many_to_many"/> " Is this ok? RE: self to self relationship - remkonoteboom - 02-07-2020 It's ugly, but harmless. The last one is unnecessary because it will never be used. If a search or an expression does not explicitly state a path, it will look for the entry with no path. That would be line #3. It should just take the first connection it can find if now item with a path can be found (we can add that later), but for now, you will need to have a "default" no-path entry. RE: self to self relationship - listy - 02-07-2020 Well at least it works, somehow. What i found is still not work as expected is (work fine for others not self_to_self): sobject - some "asset" sobject search = Search("testovy/asset") search.add_relationship_filter(sobject, path="child") Looks like it can't figure out instance type here. Or may be path is ignored This works fine. search = Search("testovy/asset_in_asset") search.add_relationship_filter(sobject, path="child") RE: self to self relationship - listy - 02-08-2020 I also tested: instance_type = 'testovy/asset_in_asset' src_sobject = 'testovy/asset?project=testovy&code=ASSET00001' dst_sobject= 'testovy/asset?project=testovy&code=ASSET00003' instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, path="child") instance.commit() And it is working Good! May be there is a bug with "add_relationship_filter"? Looks like Sobject.remove_instance() did not work too From search.py add_relationship_filter: if search_type == related_type: print "WARNING: related type and search type are the same for [%s]" % search_type my.add_id_filter(sobject.get_id()) return Looks like it checks for same realtationship, and skip path arg. May be there should be check for path, before warning? RE: self to self relationship - listy - 02-09-2020 I need to fix Sobject.remove_instance() and i am ready to production. For other things i found workarounds. Just want to make shure i am doing all the things as it meant to be, and not reinventing the wheel RE: self to self relationship - Diego - 05-19-2020 Hi Listy, Did you do any progress on the "self to self"? I did some testing because I wanted to start using the DropElementWdg to manage this relations in a similar way as the VFX plugin does with the "shot planner" tool (with collections there is custom code taking care of the path problem, see CollectionAddCmd() in src/tactic/ui/panel/collection_wdg.py). we need an asset_in_asset sType with two fields: parent_asset_code and child_asset_code (I'm using this names because they are the default names used in the collections code) as stated by Remko we need a schema connection without the path (only the first one will be used) this is because in src/pyasm/search/search.py add_related_connection() line 3771 does: Code: line 3772: self.add_related_sobject(src_sobject, src_path=src_path) the second call will fail if an entry without path does not exists. in this case only two connections are needed: Code: <connect from="prj/asset_in_asset" to="prj/asset" from_node="prj/asset_in_asset" to_node="prj/asset" relationship="code" from_col="parent_asset_code" to_col="code" path="parent" type="many_to_many"/> Now when you do something like: Code: instance_type = 'prj/asset_in_asset' add_related_connection() line 3772 will add a new asset_in_asset with the code of src_sobject in parent_asset_code and line 3773 will add the code of dst_sobject to child_asset_code. I found 3 problems with this: 1 - when you delete the parent asset it won't cascade to delete the related asset_in_asset entries because I found no way to tell tactic I want to use a specific path when deleting sObjects with include_dependencies=True so the delete operation will only use the second connection in the schema example and look only for entry where the deleted object is a child (child_asset_code) 2 - If you want to be able to use a "return" path like in Code: <connect from="mfe/asset_in_asset" to="mfe/asset" from_node="mfe/asset_in_asset" to_node="mfe/asset" relationship="code" from_col="child_asset_code" to_col="code" path="child" type="many_to_many"/> it would be impossible because you would need a different "default" (without path) schema connection: Code: <connect from="mfe/asset_in_asset" to="mfe/asset" from_node="mfe/asset_in_asset" to_node="mfe/asset" relationship="code" from_col="parent_asset_code" to_col="code" type="many_to_many"/> 3 - There are few modifications needed to DropElementAction a DropElementWdg to make it work, I will make a PR to illustrate them. If we want to make the self to self relationship to work properly there is more work to be done in search.py. Remko, do you fell e better support for self to self is needed? Do want me to open an issue for this? |