added explicit lookup_fields to entity types
This commit is contained in:
@ -677,25 +677,32 @@ impl Merger {
|
||||
let id_val = entity_fields.get("id");
|
||||
let entity_type_name = entity_type.name.as_str();
|
||||
|
||||
let mut lookup_complete = false;
|
||||
if !entity_type.lookup_fields.is_empty() {
|
||||
lookup_complete = true;
|
||||
for column in &entity_type.lookup_fields {
|
||||
match entity_fields.get(column) {
|
||||
Some(Value::Null) | None => {
|
||||
lookup_complete = false;
|
||||
break;
|
||||
let mut lookup_satisfied_keys = Vec::new();
|
||||
for parent_type_name in entity_type.hierarchy.iter().rev() {
|
||||
if let Some(parent_type) = self.db.types.get(parent_type_name) {
|
||||
if !parent_type.lookup_fields.is_empty() {
|
||||
let mut lookup_complete = true;
|
||||
for column in &parent_type.lookup_fields {
|
||||
match entity_fields.get(column) {
|
||||
Some(Value::Null) | None => {
|
||||
lookup_complete = false;
|
||||
break;
|
||||
}
|
||||
Some(Value::String(s)) if s.is_empty() => {
|
||||
lookup_complete = false;
|
||||
break;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Some(Value::String(s)) if s.is_empty() => {
|
||||
lookup_complete = false;
|
||||
break;
|
||||
if lookup_complete {
|
||||
lookup_satisfied_keys.push(&parent_type.lookup_fields);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if id_val.is_none() && !lookup_complete {
|
||||
if id_val.is_none() && lookup_satisfied_keys.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
@ -727,9 +734,9 @@ impl Merger {
|
||||
where_parts.push(format!("t1.id = {}", Self::quote_literal(id)));
|
||||
}
|
||||
|
||||
if lookup_complete {
|
||||
for lookup_fields in lookup_satisfied_keys {
|
||||
let mut lookup_predicates = Vec::new();
|
||||
for column in &entity_type.lookup_fields {
|
||||
for column in lookup_fields {
|
||||
let val = entity_fields.get(column).unwrap_or(&Value::Null);
|
||||
if column == "type" {
|
||||
lookup_predicates.push(format!("t1.\"{}\" = {}", column, Self::quote_literal(val)));
|
||||
|
||||
Reference in New Issue
Block a user