function get_dbo_establishment_with_references_flocktypes_dbo_flocktypes
Queries a Neo4j graph database to retrieve dbo_FlockTypes nodes that are connected to a specific dbo_Establishment node through a REFERENCES_FLOCKTYPES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1769 - 1776
simple
Purpose
This function is designed to traverse a graph database relationship between establishment and flock type entities. It's useful for retrieving all flock types associated with a particular establishment in what appears to be an agricultural or livestock management system. The function supports pagination through a limit parameter to control the number of results returned.
Source Code
def get_dbo_establishment_with_references_flocktypes_dbo_flocktypes(source_id, limit=100):
"""Get dbo_FlockTypes nodes connected to a dbo_Establishment via REFERENCES_FLOCKTYPES"""
query = """
MATCH (source:dbo_Establishment {id: $source_id})-[r:REFERENCES_FLOCKTYPES]->(target:dbo_FlockTypes)
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 of the dbo_Establishment node from which to start the traversal. This should be a string or integer value that matches the 'id' property of an existing Establishment node in the Neo4j database.
limit: Maximum number of dbo_FlockTypes nodes to return. Defaults to 100. This parameter helps control query performance and result set size. Must be a positive integer.
Return Value
Returns the result of run_query() function execution, which typically contains a list or collection of dbo_FlockTypes nodes (target nodes) that match the query criteria. The exact return type depends on the run_query() implementation, but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of each matched dbo_FlockTypes node. Returns an empty collection if no matching relationships are found.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Get flock types for establishment with ID '12345'
result = get_dbo_establishment_with_references_flocktypes_dbo_flocktypes('12345')
# Example 2: Limit results to 50 flock types
result = get_dbo_establishment_with_references_flocktypes_dbo_flocktypes('12345', limit=50)
# Example 3: Process the results
for record in result:
flock_type = record['target']
print(f"Flock Type ID: {flock_type['id']}")
Best Practices
- Always validate that source_id exists in the database before calling this function to avoid empty results
- Consider adjusting the limit parameter based on expected data volume to optimize query performance
- Ensure proper error handling around this function call as database connections can fail
- The run_query() function should handle connection pooling and proper session management
- Consider adding pagination support (offset parameter) if dealing with large result sets
- Validate that the source_id parameter is properly sanitized, though parameterized queries provide protection against injection attacks
- Monitor query performance and consider adding indexes on the 'id' property of dbo_Establishment nodes if queries are slow
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_flocks_with_references_establishment_dbo_establishment 90.6% similar
-
function get_dbo_flocks_with_references_flocktypes_dbo_flocktypes 88.3% similar
-
function get_dbo_houses_with_references_flocktypes_dbo_flocktypes 86.8% similar
-
function create_references_flocktypes_relationship 85.2% similar
-
function get_all_dbo_flocktypes 82.1% similar