fixed issue with organization_id auto-setting in merge
This commit is contained in:
@ -129,6 +129,25 @@ impl Merger {
|
||||
crate::drop::Drop::success_with_val(stripped_val)
|
||||
}
|
||||
|
||||
fn inject_organization_id(
|
||||
relative: &mut serde_json::Map<String, Value>,
|
||||
entity_fields: &serde_json::Map<String, Value>,
|
||||
schema: &Arc<crate::database::schema::Schema>,
|
||||
) {
|
||||
if !relative.contains_key("organization_id") {
|
||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
||||
if let Some(compiled_props) = schema.obj.compiled_properties.get() {
|
||||
if let Some(org_schema) = compiled_props.get("organization_id") {
|
||||
if org_schema.obj.const_.is_some() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
relative.insert("organization_id".to_string(), org_id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn merge_internal(
|
||||
&self,
|
||||
mut schema: Arc<crate::database::schema::Schema>,
|
||||
@ -313,11 +332,7 @@ impl Merger {
|
||||
let parent_is_source = edge.forward;
|
||||
|
||||
if parent_is_source {
|
||||
if !relative.contains_key("organization_id") {
|
||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
||||
relative.insert("organization_id".to_string(), org_id.clone());
|
||||
}
|
||||
}
|
||||
Self::inject_organization_id(&mut relative, &entity_fields, &rel_schema);
|
||||
|
||||
let mut merged_relative = match self.merge_internal(
|
||||
rel_schema.clone(),
|
||||
@ -338,11 +353,7 @@ impl Merger {
|
||||
);
|
||||
entity_response.insert(relation_name, Value::Object(merged_relative));
|
||||
} else {
|
||||
if !relative.contains_key("organization_id") {
|
||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
||||
relative.insert("organization_id".to_string(), org_id.clone());
|
||||
}
|
||||
}
|
||||
Self::inject_organization_id(&mut relative, &entity_fields, &rel_schema);
|
||||
|
||||
Self::apply_entity_relation(
|
||||
&mut relative,
|
||||
@ -401,22 +412,6 @@ impl Merger {
|
||||
if let Some(compiled_edges) = schema.obj.compiled_edges.get() {
|
||||
if let Some(edge) = compiled_edges.get(&relation_name) {
|
||||
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||
let mut relative_responses = Vec::new();
|
||||
for relative_item_val in relative_arr {
|
||||
if let Value::Object(mut relative_item) = relative_item_val {
|
||||
if !relative_item.contains_key("organization_id") {
|
||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
||||
relative_item.insert("organization_id".to_string(), org_id.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Self::apply_entity_relation(
|
||||
&mut relative_item,
|
||||
&relation.source_columns,
|
||||
&relation.destination_columns,
|
||||
&entity_fields,
|
||||
);
|
||||
|
||||
let mut item_schema = rel_schema.clone();
|
||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) =
|
||||
&rel_schema.obj.type_
|
||||
@ -428,8 +423,20 @@ impl Merger {
|
||||
}
|
||||
}
|
||||
|
||||
let mut relative_responses = Vec::new();
|
||||
for relative_item_val in relative_arr {
|
||||
if let Value::Object(mut relative_item) = relative_item_val {
|
||||
Self::inject_organization_id(&mut relative_item, &entity_fields, &item_schema);
|
||||
|
||||
Self::apply_entity_relation(
|
||||
&mut relative_item,
|
||||
&relation.source_columns,
|
||||
&relation.destination_columns,
|
||||
&entity_fields,
|
||||
);
|
||||
|
||||
let merged_relative = match self.merge_internal(
|
||||
item_schema,
|
||||
item_schema.clone(),
|
||||
Value::Object(relative_item),
|
||||
notifications,
|
||||
)? {
|
||||
|
||||
Reference in New Issue
Block a user