Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8a15a82ef | |||
| 8dcc714963 | |||
| f87ac81f3b |
@ -1003,6 +1003,7 @@
|
|||||||
" JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id",
|
" JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id",
|
||||||
" WHERE",
|
" WHERE",
|
||||||
" NOT entity_6.archived",
|
" NOT entity_6.archived",
|
||||||
|
" AND relationship_5.target_type = 'address'",
|
||||||
" AND relationship_5.source_id = entity_3.id),",
|
" AND relationship_5.source_id = entity_3.id),",
|
||||||
" 'age', person_1.age,",
|
" 'age', person_1.age,",
|
||||||
" 'archived', entity_3.archived,",
|
" 'archived', entity_3.archived,",
|
||||||
@ -1094,6 +1095,7 @@
|
|||||||
" JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id",
|
" JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id",
|
||||||
" WHERE",
|
" WHERE",
|
||||||
" NOT entity_20.archived",
|
" NOT entity_20.archived",
|
||||||
|
" AND relationship_19.target_type = 'email_address'",
|
||||||
" AND relationship_19.source_id = entity_3.id),",
|
" AND relationship_19.source_id = entity_3.id),",
|
||||||
" 'first_name', person_1.first_name,",
|
" 'first_name', person_1.first_name,",
|
||||||
" 'id', entity_3.id,",
|
" 'id', entity_3.id,",
|
||||||
@ -1127,6 +1129,7 @@
|
|||||||
" JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id",
|
" JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id",
|
||||||
" WHERE",
|
" WHERE",
|
||||||
" NOT entity_25.archived",
|
" NOT entity_25.archived",
|
||||||
|
" AND relationship_24.target_type = 'phone_number'",
|
||||||
" AND relationship_24.source_id = entity_3.id),",
|
" AND relationship_24.source_id = entity_3.id),",
|
||||||
" 'type', entity_3.type",
|
" 'type', entity_3.type",
|
||||||
")",
|
")",
|
||||||
@ -1240,6 +1243,7 @@
|
|||||||
" JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id",
|
" JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id",
|
||||||
" WHERE",
|
" WHERE",
|
||||||
" NOT entity_6.archived",
|
" NOT entity_6.archived",
|
||||||
|
" AND relationship_5.target_type = 'address'",
|
||||||
" AND relationship_5.source_id = entity_3.id),",
|
" AND relationship_5.source_id = entity_3.id),",
|
||||||
" 'age', person_1.age,",
|
" 'age', person_1.age,",
|
||||||
" 'archived', entity_3.archived,",
|
" 'archived', entity_3.archived,",
|
||||||
@ -1332,6 +1336,7 @@
|
|||||||
" JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id",
|
" JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id",
|
||||||
" WHERE",
|
" WHERE",
|
||||||
" NOT entity_20.archived",
|
" NOT entity_20.archived",
|
||||||
|
" AND relationship_19.target_type = 'email_address'",
|
||||||
" AND relationship_19.source_id = entity_3.id),",
|
" AND relationship_19.source_id = entity_3.id),",
|
||||||
" 'first_name', person_1.first_name,",
|
" 'first_name', person_1.first_name,",
|
||||||
" 'id', entity_3.id,",
|
" 'id', entity_3.id,",
|
||||||
@ -1366,6 +1371,7 @@
|
|||||||
" JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id",
|
" JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id",
|
||||||
" WHERE",
|
" WHERE",
|
||||||
" NOT entity_25.archived",
|
" NOT entity_25.archived",
|
||||||
|
" AND relationship_24.target_type = 'phone_number'",
|
||||||
" AND relationship_24.source_id = entity_3.id),",
|
" AND relationship_24.source_id = entity_3.id),",
|
||||||
" 'type', entity_3.type",
|
" 'type', entity_3.type",
|
||||||
")",
|
")",
|
||||||
@ -1441,7 +1447,9 @@
|
|||||||
"FROM agreego.contact contact_1",
|
"FROM agreego.contact contact_1",
|
||||||
"JOIN agreego.relationship relationship_2 ON relationship_2.id = contact_1.id",
|
"JOIN agreego.relationship relationship_2 ON relationship_2.id = contact_1.id",
|
||||||
"JOIN agreego.entity entity_3 ON entity_3.id = relationship_2.id",
|
"JOIN agreego.entity entity_3 ON entity_3.id = relationship_2.id",
|
||||||
"WHERE NOT entity_3.archived)"
|
"WHERE",
|
||||||
|
" NOT entity_3.archived",
|
||||||
|
" AND relationship_2.target_type = 'email_address')"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -496,6 +496,7 @@ impl<'a> Compiler<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.compile_filter_conditions(r#type, type_aliases, &node, &base_alias, &mut where_clauses);
|
self.compile_filter_conditions(r#type, type_aliases, &node, &base_alias, &mut where_clauses);
|
||||||
|
self.compile_polymorphic_bounds(r#type, type_aliases, &node, &mut where_clauses);
|
||||||
self.compile_relation_conditions(
|
self.compile_relation_conditions(
|
||||||
r#type,
|
r#type,
|
||||||
type_aliases,
|
type_aliases,
|
||||||
@ -507,6 +508,54 @@ impl<'a> Compiler<'a> {
|
|||||||
Ok(where_clauses)
|
Ok(where_clauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compile_polymorphic_bounds(
|
||||||
|
&self,
|
||||||
|
_type: &crate::database::r#type::Type,
|
||||||
|
type_aliases: &std::collections::HashMap<String, String>,
|
||||||
|
node: &Node,
|
||||||
|
where_clauses: &mut Vec<String>,
|
||||||
|
) {
|
||||||
|
if let Some(edges) = node.schema.obj.compiled_edges.get() {
|
||||||
|
if let Some(props) = node.schema.obj.compiled_properties.get() {
|
||||||
|
for (prop_name, edge) in edges {
|
||||||
|
if let Some(prop_schema) = props.get(prop_name) {
|
||||||
|
// Determine if the property schema resolves to a physical Database Entity
|
||||||
|
let mut bound_type_name = None;
|
||||||
|
if let Some(family_target) = prop_schema.obj.family.as_ref() {
|
||||||
|
bound_type_name = Some(family_target.split('.').next_back().unwrap_or(family_target).to_string());
|
||||||
|
} else if let Some(lookup_key) = prop_schema.obj.id.as_ref().or(prop_schema.obj.r#ref.as_ref()) {
|
||||||
|
bound_type_name = Some(lookup_key.split('.').next_back().unwrap_or(lookup_key).to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(type_name) = bound_type_name {
|
||||||
|
// Ensure this type actually exists
|
||||||
|
if self.db.types.contains_key(&type_name) {
|
||||||
|
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||||
|
let mut poly_col = None;
|
||||||
|
let mut table_to_alias = "";
|
||||||
|
|
||||||
|
if edge.forward && relation.source_columns.len() > 1 {
|
||||||
|
poly_col = Some(&relation.source_columns[1]); // e.g., target_type
|
||||||
|
table_to_alias = &relation.source_type; // e.g., relationship
|
||||||
|
} else if !edge.forward && relation.destination_columns.len() > 1 {
|
||||||
|
poly_col = Some(&relation.destination_columns[1]); // e.g., source_type
|
||||||
|
table_to_alias = &relation.destination_type; // e.g., relationship
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(col) = poly_col {
|
||||||
|
if let Some(alias) = type_aliases.get(table_to_alias).or_else(|| type_aliases.get(&node.parent_alias)) {
|
||||||
|
where_clauses.push(format!("{}.{} = '{}'", alias, col, type_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn resolve_filter_alias(
|
fn resolve_filter_alias(
|
||||||
r#type: &crate::database::r#type::Type,
|
r#type: &crate::database::r#type::Type,
|
||||||
type_aliases: &std::collections::HashMap<String, String>,
|
type_aliases: &std::collections::HashMap<String, String>,
|
||||||
|
|||||||
Reference in New Issue
Block a user