<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get the relationship between feature classes by arcpy or sql in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291333#M67698</link>
    <description>&lt;P&gt;&lt;STRONG&gt;i have tried the last code at this page with sql developer but it does not work with me .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Did it work with u ? Do u have idea ,how could I write correct code in sql and let it work to find the relationships between feature classes ?&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 20 May 2023 05:25:43 GMT</pubDate>
    <dc:creator>spiderman90</dc:creator>
    <dc:date>2023-05-20T05:25:43Z</dc:date>
    <item>
      <title>How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291250#M67691</link>
      <description>&lt;P&gt;Hello ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to get a list of relationships between all feature classes with origin name and destination name&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am still new in arcpy ,so I need help&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would like to have script to do it by arcpy and I am using arcmap .&lt;/P&gt;&lt;P&gt;and I would like to ask if there is queries that get the relationship between feature classes by sql developer ?&amp;nbsp;&lt;BR /&gt;thanks in advance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 19:37:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291250#M67691</guid>
      <dc:creator>spiderman90</dc:creator>
      <dc:date>2023-05-19T19:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291258#M67692</link>
      <description>&lt;P&gt;My code from &lt;A href="https://community.esri.com/t5/python-ideas/add-function-list-relationship-classes/idi-p/1064766" target="_blank" rel="noopener"&gt;this Idea&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def listRelationshipClasses(database):
    """Returns a list of dictionaries describing the relationship classes inside the given database.

    Tested with SDE and FGDB

    database: str, path to the database

    """
    desc = arcpy.da.Describe(database)
    parents = [desc] + [c for c in desc["children"] if c["dataElementType"] == "DEFeatureDataset"]
    rs = []
    for p in parents:
        rs += [c for c in p["children"] if c["dataElementType"] == "DERelationshipClass"]
    return rs


listRelationshipClasses("Path\to\your\database.gdb")
listRelationshipClasses("Path\to\your\database.sde")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os, pprint

all_rs = listRelationshipClasses("path/to/your/database.sde")  # see above

pprint.pprint(all_rs[0])

# filter by name
rs = [r for r in all_rs if r["name"] == "FilterName"]
rs = [r for r in all_rs if "PartOfTheName" in rs["name"]]

# filter by cardinality
rs = [r for r in all_rs if r["cardinality"] == "OneToOne"]

# filter by origin or destination table
rs = [r for r in all_rs if "OriginTableName" in r["originClassNames"]]
rs = [r for r in all_rs if "DestinationTableName" in r["destinationClassNames"]]
rs = [r for r in all_rs if "OriginTableName" in r["originClassNames"] and "DestinationTableName" in r["destinationClassNames"]]

# filter by dataset
rs = [r for r in all_rs if os.path.basename(r["path"]) == "DatasetName"]

# filter by flags
rs = [r for r in all_rs if r["isComposite"]]
rs = [r for r in all_rs if not r["isComposite"]]
# other flags: isAttachmentRelationship, isAttributed, isReflexive, isVersioned, canVersion, changeTracked&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 19 May 2023 20:01:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291258#M67692</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-19T20:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291260#M67693</link>
      <description>&lt;P&gt;And for SQL:&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/manage-data/using-sql-with-gdbs/returning-a-list-of-relationship-classes.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/en/arcmap/latest/manage-data/using-sql-with-gdbs/returning-a-list-of-relationship-classes.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 20:02:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291260#M67693</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-19T20:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291333#M67698</link>
      <description>&lt;P&gt;&lt;STRONG&gt;i have tried the last code at this page with sql developer but it does not work with me .&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Did it work with u ? Do u have idea ,how could I write correct code in sql and let it work to find the relationships between feature classes ?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 05:25:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291333#M67698</guid>
      <dc:creator>spiderman90</dc:creator>
      <dc:date>2023-05-20T05:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291334#M67699</link>
      <description>&lt;P&gt;Sorry for asking&amp;nbsp;&lt;/P&gt;&lt;P&gt;but should I add only the path of sde and the code above and it should works but where should does save the results ?&amp;nbsp;&lt;BR /&gt;How will the result appear for me ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;sorry am not familiar with working with Python in arcmap ,and I am not sure how to let this code and get the result .&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 07:10:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291334#M67699</guid>
      <dc:creator>spiderman90</dc:creator>
      <dc:date>2023-05-20T07:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291345#M67700</link>
      <description>&lt;P&gt;The function will return a list of dictionaries that describe your relationship classes. You can analyse this list in the Python Window, but if you want to save it, you'll have to write extra code. Something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;database = "G:/ArcGIS/projects/Test/Test.gdb"
out_csv = "G:/ArcGIS/projects/Test/Relationships.csv"

all_rs = listRelationshipClasses(database)

lines = ["Name", "Origin", "Destination", "Cardinality", "Composite"]
for rs in all_rs:
    lines.append(  [rs["name"], rs["originClassNames"][0], rs["destinationClassNames"][0], rs["cardinality"], str(rs["isComposite"])] )

with open(out_csv, "w") as f:
    for line in lines:
        f.write(",".join(line) + "\n")&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 20 May 2023 10:22:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291345#M67700</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-20T10:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291346#M67701</link>
      <description>&lt;P&gt;I have no idea, that's just the official documentation I found for this.&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 10:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291346#M67701</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-20T10:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the relationship between feature classes by arcpy or sql</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291351#M67703</link>
      <description>&lt;P&gt;It is not working but thanks for reply&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 13:17:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-the-relationship-between-feature/m-p/1291351#M67703</guid>
      <dc:creator>spiderman90</dc:creator>
      <dc:date>2023-05-20T13:17:46Z</dc:date>
    </item>
  </channel>
</rss>

