function get_dbo_establishment_with_references_municipalities_reference_municipalities
Retrieves Reference_Municipalities nodes from a Neo4j graph database that are connected to a specific dbo_Establishment node via a REFERENCES_MUNICIPALITIES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1737 - 1744
simple
Purpose
This function queries a Neo4j graph database to find all municipality reference nodes associated with a particular establishment. It's useful for discovering which municipalities are referenced by or related to a specific establishment entity, with configurable result limits for performance optimization.
Source Code
def get_dbo_establishment_with_references_municipalities_reference_municipalities(source_id, limit=100):
"""Get Reference_Municipalities nodes connected to a dbo_Establishment via REFERENCES_MUNICIPALITIES"""
query = """
MATCH (source:dbo_Establishment {id: $source_id})-[r:REFERENCES_MUNICIPALITIES]->(target:Reference_Municipalities)
RETURN target
LIMIT $limit
"""
return run_query(query, {"source_id": source_id, "limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
source_id |
- | - | positional_or_keyword |
limit |
- | 100 | positional_or_keyword |
Parameter Details
source_id: The unique identifier (id property) of the dbo_Establishment node from which to find connected Reference_Municipalities nodes. Expected to be a string or integer that matches an existing establishment ID in the database.
limit: Maximum number of Reference_Municipalities nodes to return. Defaults to 100. Used to control query performance and result set size. Must be a positive integer.
Return Value
Returns the result of run_query() function, which typically contains a list or collection of Reference_Municipalities nodes that match the query criteria. The exact return type depends on the run_query() implementation, but likely returns a list of dictionaries or Neo4j Record objects containing the properties of each target Reference_Municipalities node.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
from neo4j import GraphDatabase
# Get municipalities referenced by establishment with ID '12345'
result = get_dbo_establishment_with_references_municipalities_reference_municipalities('12345', limit=50)
# Process the results
for record in result:
municipality = record['target']
print(f"Municipality: {municipality}")
# Get default 100 results
result_default = get_dbo_establishment_with_references_municipalities_reference_municipalities('67890')
Best Practices
- Ensure the source_id parameter matches an existing dbo_Establishment node ID to avoid empty results
- Adjust the limit parameter based on expected result size and performance requirements
- Handle cases where no relationships exist (empty result set) in calling code
- Consider adding error handling for database connection issues
- Validate that the run_query() function is properly configured with Neo4j connection details before calling this function
- Be aware that the limit is applied after the relationship traversal, so all matching relationships are found but only 'limit' results are returned
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_references_municipalities_relationship 84.2% similar
-
function get_dbo_houses_with_references_establishment_dbo_establishment 82.7% similar
-
function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment 79.6% similar
-
function get_dbo_tnv_with_references_establishment_dbo_establishment 77.8% similar
-
function get_all_reference_municipalities 77.5% similar