added defaults support for lookups properly
This commit is contained in:
@ -335,16 +335,7 @@ impl Merger {
|
||||
}
|
||||
}
|
||||
|
||||
// Hydrate missing fields from field_defaults for entity_type and its hierarchy
|
||||
for parent_type_name in &type_def.hierarchy {
|
||||
if let Some(parent_type) = self.db.types.get(parent_type_name) {
|
||||
for (k, v) in &parent_type.field_defaults {
|
||||
if !entity_fields.contains_key(k) {
|
||||
entity_fields.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let mut current_org_id = None;
|
||||
if let Some(compiled_props) = schema.obj.compiled_properties.get() {
|
||||
@ -772,7 +763,10 @@ impl Merger {
|
||||
if !parent_type.lookup_fields.is_empty() {
|
||||
let mut lookup_complete = true;
|
||||
for column in &parent_type.lookup_fields {
|
||||
match entity_fields.get(column) {
|
||||
let val = entity_fields.get(column).or_else(|| {
|
||||
parent_type.field_defaults.get(column)
|
||||
});
|
||||
match val {
|
||||
Some(Value::Null) | None => {
|
||||
lookup_complete = false;
|
||||
break;
|
||||
@ -785,7 +779,7 @@ impl Merger {
|
||||
}
|
||||
}
|
||||
if lookup_complete {
|
||||
lookup_satisfied_keys.push(&parent_type.lookup_fields);
|
||||
lookup_satisfied_keys.push((&parent_type.lookup_fields, parent_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -823,10 +817,13 @@ impl Merger {
|
||||
where_parts.push(format!("t1.id = {}", Self::quote_literal(id)));
|
||||
}
|
||||
|
||||
for lookup_fields in lookup_satisfied_keys {
|
||||
for (lookup_fields, parent_type) in lookup_satisfied_keys {
|
||||
let mut lookup_predicates = Vec::new();
|
||||
for column in lookup_fields {
|
||||
let val = entity_fields.get(column).unwrap_or(&Value::Null);
|
||||
let val = entity_fields
|
||||
.get(column)
|
||||
.or_else(|| parent_type.field_defaults.get(column))
|
||||
.unwrap_or(&Value::Null);
|
||||
if column == "type" {
|
||||
lookup_predicates.push(format!("t1.\"{}\" = {}", column, Self::quote_literal(val)));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user