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) |
self to self relationship - listy - 11-14-2019 Hello Everyone! Today i have been busy doing many_to_many relationship. I need to do Asset in Asset relationship. Everything is fine when i do Texture in Asset, but when i need to do Asset in Asset i can't tell tactic to use right columns. Schema example: Code: <search_type name="dolly3d/assets" xpos="303" ypos="236"/> Thanks. RE: self to self relationship - Diego - 11-15-2019 Hi, Last time I tried Many to many on the same sType is handled through collections. It uses the parent_asset_code and child_asset_code columns <connect from="prj/asset_in_asset" to="prj/asset" relationship="code" from_col="parent_asset_code" to_col="code"/> <connect from="prj/asset_in_asset" to="prj/asset" relationship="code" from_col="child_asset_code" to_col="code"/> You should select "support collections" when creating the sType, or simply add a boolean custom column called "_is_collection" if the sType was already created. Then create your asset_in_asset sType with the parent_asset_code and child_asset_code columns and edit your schema accordingly. I'm not sure this is still supported! RE: self to self relationship - listy - 11-15-2019 (11-15-2019, 10:52 AM)Diego Wrote: Hi,Collections is never documented anywhere, so i don't know how to use it properly, or use it in productuon... RE: self to self relationship - remkonoteboom - 11-15-2019 Collections are a more formal implementation of what you are trying to do, however, there is nothing magic about them. There are somethings to be aware of. Although connections between sobjects specify a direction where "from" is the child and "to" is the parent, the expression language and other functions allow for a connections to go both ways. For example, both are possible with a single connection: @SOBJECT(vfx/asset.sthpw/task) @SOBJECT(sthpw/task.vfx/asset) This presents a problem with the example Diego provided. How does the expression language know which "path" to take because both connections satisfy the above expressions. By default the expression language will take the first definition. What is needed is a way to specify which connection to use. This is done with the "path" attribute. <connect from="prj/asset_in_asset" to="prj/asset" relationship="code" from_col="parent_asset_code" to_col="code" path="parent"/> <connect from="prj/asset_in_asset" to="prj/asset" relationship="code" from_col="child_asset_code" to_col="code" path="child"/> So, in the expression language, you could use: @SOBJECT(prj/asset.parent:prj/asset_in_asset.child:prj/asset) You will also see other functions in the api which have a "path" argument. This refers to the above. In the case of connection an table to itself, you must use the path attribute. RE: self to self relationship - Celton McGrath - 11-15-2019 Hi Listy, I want to add that collections are not special from a database perspective - they are an example of the many-to-many concept. However, TACTIC does contain special UI for viewing and maintaining collections. The caveat will be that currently the default icon for the collection is a folder icon, but there is no reason that the collection could use its own thumbnail. - Celton RE: self to self relationship - listy - 11-17-2019 Hello again! I did some changes to schema and my stypes: Code: <schema> skey = ["dolly3d/assets?project=dolly3d&code=ASSETS00577"] assets = server.eval("@SOBJECT(dolly3d/assets.parent:dolly3d/assets_in_assets.child:dolly3d/assets)", skey) The assets result is asset on with given search key. A am doing somethig wrong? server.eval("@SOBJECT(dolly3d/assets['code', 'ASSETS00577'].parent:dolly3d/assets_in_assets.child:dolly3d/assets)") Giving me proper results though RE: self to self relationship - remkonoteboom - 11-18-2019 What does: assets = server.eval("@SOBJECT(dolly3d/assets)", skey) give you? Just FYI, there is an extremelly useful feature in expressions, especially when you are navigating connections. TACTIC caches all the relationships between sobjects as it evaluates the expression. While the API does not have access to this yes, we have mapped the function onto the Search object in 4.7. So instead, you would call: server.get_eval_cache("@SOBJECT(dolly3d/assets['code', 'ASSETS00577'].parent:dolly3d/assets_in_assets.child:dolly3d/assets)") which would return a complicated dictionary with all the relationships between all the sobjects found. RE: self to self relationship - listy - 11-18-2019 I AM ON TACTIC 4.5.01 Hi. It give me the self object, not his children: [{'__search_key__': 'dolly3d/assets?project=dolly3d&code=ASSETS00577', '__search_type__': 'dolly3d/assets?project=dolly3d', 'assets_category_code': 'locations', 'code': 'ASSETS00577', 'description': u'', 'id': 577, 'keywords': u'', 'login': '', 'name': 'witch_house_inside', 'pipeline_code': 'dolly3d/assets', 'relative_dir': 'dolly3d/assets', 's_status': '', 'texture_drop': '', 'timestamp': '2019-10-11 20:05:58.005634'}] server.eval("@SOBJECT(dolly3d/assets.parent:dolly3d/assets_in_assets.child:dolly3d/assets)") Without adding search_key: Fault: <Fault 1: 'Search type [dolly3d/assets_in_assets] is not related to search_type [dolly3d/assets]'> ALSO, looks like when i call .parent tactic thiking there is another parent, my assets category. server.eval("@SOBJECT(dolly3d/assets['code', 'ASSETS00577'].parent)") [{'__search_key__': 'complex/assets_category?project=dolly3d&code=locations', '__search_type__': 'complex/assets_category?project=dolly3d', 'code': 'locations', 'description': '', 'id': 4, 'keywords': '', 'login': '', 'name': 'Locations', 's_status': '', 'timestamp': '2019-03-07 02:18:02.369421'}] RE: self to self relationship - remkonoteboom - 11-18-2019 When skey = "dolly3d/assets?project=dolly3d&code=ASSETS00577" The expression "@SOBJECT(dolly3d/assets)" should return itself. It is functionally the same as "@SOBJECT()". What does this give? assets = server.eval("@SOBJECT(dolly3d/assets).dolly3d/assets_in_assets", skey) Is it a list of "assets_in_assets" that are related by parent? RE: self to self relationship - listy - 11-18-2019 If i run it with search_keys it gives me the same. Without: assets = server.eval("@SOBJECT(dolly3d/assets.dolly3d/assets_in_assets)") [{'__search_key__': 'dolly3d/assets_in_assets?project=dolly3d&code=ASSETS_IN_ASSETS00017', '__search_type__': 'dolly3d/assets_in_assets?project=dolly3d', 'child_assets_code': 'ASSETS00163', 'code': 'ASSETS_IN_ASSETS00017', 'id': 17, 'parent_assets_code': 'ASSETS00577', 'relative_dir': 'dolly3d/assets_in_assets', 's_status': '', 'timestamp': '2019-11-17 17:10:45.390540'}] (A have single ASSETS_IN_ASSETS00017 in db) I fount that i fired wrong expression, this is with one you wrote: skey = ["dolly3d/assets?project=dolly3d&code=ASSETS00577"] assets = server.eval("@SOBJECT(dolly3d/assets).dolly3d/assets_in_assets", skey) Fault: <Fault 1: 'Could not evaluate [<pyasm.search.search.SObject object at 0x7f88040a0290> .dolly3d """/""" assets_in_assets] in expression [@SOBJECT(dolly3d/assets).dolly3d/assets_in_assets] due to error [invalid syntax (<string>, line 1)]'> |