function get_dbo_flocks_with_references_houses_dbo_houses
Retrieves dbo_Houses nodes from a Neo4j graph database that are connected to a specific dbo_Flocks node via a REFERENCES_HOUSES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1929 - 1936
simple
Purpose
This function queries a Neo4j graph database to find all house records (dbo_Houses) that are referenced by a specific flock record (dbo_Flocks). It's designed for traversing relationships in a poultry or livestock management system where flocks are associated with specific housing facilities. The function supports pagination through a limit parameter to control the number of results returned.
Source Code
def get_dbo_flocks_with_references_houses_dbo_houses(source_id, limit=100):
"""Get dbo_Houses nodes connected to a dbo_Flocks via REFERENCES_HOUSES"""
query = """
MATCH (source:dbo_Flocks {id: $source_id})-[r:REFERENCES_HOUSES]->(target:dbo_Houses)
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_Flocks node from which to find connected houses. This should be a string or integer value that matches the 'id' property of a node in the Neo4j database.
limit: Maximum number of dbo_Houses nodes to return. Defaults to 100. This parameter controls pagination and prevents returning excessively large result sets. Must be a positive integer.
Return Value
Returns the result of run_query() function, which typically contains a list or collection of dbo_Houses 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 target dbo_Houses node. Returns an empty collection if no matching houses are found or if the source_id doesn't exist.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Get houses for a specific flock with default limit
houses = get_dbo_flocks_with_references_houses_dbo_houses(source_id="flock_12345")
# Example 2: Get houses with custom limit
houses = get_dbo_flocks_with_references_houses_dbo_houses(source_id="flock_12345", limit=50)
# Example 3: Process results
for house in houses:
print(f"House ID: {house['target']['id']}")
print(f"House Name: {house['target'].get('name', 'N/A')}")
Best Practices
- Always validate that source_id exists before calling this function to avoid unnecessary database queries
- Use appropriate limit values based on expected result sizes to optimize performance and memory usage
- Handle empty results gracefully as the source_id may not have any connected houses
- Consider implementing error handling for database connection failures
- Ensure the run_query() function properly manages Neo4j sessions and transactions
- Be aware that this function depends on the external run_query() function which must be properly implemented
- Consider adding indexes on the 'id' property of dbo_Flocks nodes for better query performance
- The limit parameter provides basic pagination but doesn't support offset - consider implementing skip/offset for full pagination support
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_houses_with_references_flocktypes_dbo_flocktypes 92.5% similar
-
function create_references_houses_relationship_v2 83.8% similar
-
function get_dbo_treatments_with_references_flocks_dbo_flocks 81.1% similar
-
function get_dbo_concepthouses_with_references_houses_dbo_houses 80.8% similar
-
function get_dbo_flocks_with_references_flocktypes_dbo_flocktypes 80.2% similar