function get_dbo_houses_with_references_flocktypes_dbo_flocktypes
Queries a Neo4j graph database to retrieve dbo_FlockTypes nodes that are connected to a specific dbo_Houses node via a REFERENCES_FLOCKTYPES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1993 - 2000
simple
Purpose
This function is designed to traverse a graph database relationship between house records and flock type records. It's useful for applications that need to understand what types of flocks are associated with specific houses in a poultry or livestock management system. The function allows limiting the number of results returned to manage query performance and result set size.
Source Code
def get_dbo_houses_with_references_flocktypes_dbo_flocktypes(source_id, limit=100):
"""Get dbo_FlockTypes nodes connected to a dbo_Houses via REFERENCES_FLOCKTYPES"""
query = """
MATCH (source:dbo_Houses {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_Houses node from which to start the relationship traversal. This should be a value that matches the 'id' property of a dbo_Houses node in the Neo4j database. Expected type is typically string or integer depending on the database schema.
limit: Maximum number of dbo_FlockTypes nodes to return from the query. Defaults to 100. This parameter helps control query performance and prevents returning excessively large result sets. Must be a positive integer.
Return Value
Returns the result of the run_query function, which typically contains a list or collection of dbo_FlockTypes nodes that match the query criteria. The exact return type depends on the implementation of run_query, but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of the target dbo_FlockTypes nodes. 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 a specific house
house_id = "HOUSE_001"
flock_types = get_dbo_houses_with_references_flocktypes_dbo_flocktypes(house_id)
# Example 2: Limit results to 50
house_id = "HOUSE_002"
flock_types = get_dbo_houses_with_references_flocktypes_dbo_flocktypes(house_id, limit=50)
# Example 3: Process results
for record in flock_types:
flock_type_node = record['target']
print(f"Flock Type: {flock_type_node}")
Best Practices
- Always validate that source_id exists in the database before calling this function to avoid empty result sets
- Consider adjusting the limit parameter based on expected data volume and performance requirements
- Ensure proper error handling around the run_query function call to catch database connection issues
- The function depends on run_query being properly implemented with Neo4j connection management
- Consider adding input validation for source_id and limit parameters to prevent invalid queries
- Be aware that this function only traverses outgoing REFERENCES_FLOCKTYPES relationships from dbo_Houses nodes
- Monitor query performance if the limit is set to very high values or if the graph has many relationships
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_flocks_with_references_houses_dbo_houses 92.5% similar
-
function get_dbo_flocks_with_references_flocktypes_dbo_flocktypes 89.9% similar
-
function get_dbo_establishment_with_references_flocktypes_dbo_flocktypes 86.8% similar
-
function create_references_flocktypes_relationship_v1 85.4% similar
-
function get_all_dbo_flocktypes 84.2% similar