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)
|
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(
|
pub(crate) fn merge_internal(
|
||||||
&self,
|
&self,
|
||||||
mut schema: Arc<crate::database::schema::Schema>,
|
mut schema: Arc<crate::database::schema::Schema>,
|
||||||
@ -313,11 +332,7 @@ impl Merger {
|
|||||||
let parent_is_source = edge.forward;
|
let parent_is_source = edge.forward;
|
||||||
|
|
||||||
if parent_is_source {
|
if parent_is_source {
|
||||||
if !relative.contains_key("organization_id") {
|
Self::inject_organization_id(&mut relative, &entity_fields, &rel_schema);
|
||||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
|
||||||
relative.insert("organization_id".to_string(), org_id.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut merged_relative = match self.merge_internal(
|
let mut merged_relative = match self.merge_internal(
|
||||||
rel_schema.clone(),
|
rel_schema.clone(),
|
||||||
@ -338,11 +353,7 @@ impl Merger {
|
|||||||
);
|
);
|
||||||
entity_response.insert(relation_name, Value::Object(merged_relative));
|
entity_response.insert(relation_name, Value::Object(merged_relative));
|
||||||
} else {
|
} else {
|
||||||
if !relative.contains_key("organization_id") {
|
Self::inject_organization_id(&mut relative, &entity_fields, &rel_schema);
|
||||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
|
||||||
relative.insert("organization_id".to_string(), org_id.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Self::apply_entity_relation(
|
Self::apply_entity_relation(
|
||||||
&mut relative,
|
&mut relative,
|
||||||
@ -401,14 +412,21 @@ impl Merger {
|
|||||||
if let Some(compiled_edges) = schema.obj.compiled_edges.get() {
|
if let Some(compiled_edges) = schema.obj.compiled_edges.get() {
|
||||||
if let Some(edge) = compiled_edges.get(&relation_name) {
|
if let Some(edge) = compiled_edges.get(&relation_name) {
|
||||||
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||||
|
let mut item_schema = rel_schema.clone();
|
||||||
|
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) =
|
||||||
|
&rel_schema.obj.type_
|
||||||
|
{
|
||||||
|
if t == "array" {
|
||||||
|
if let Some(items_def) = &rel_schema.obj.items {
|
||||||
|
item_schema = items_def.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut relative_responses = Vec::new();
|
let mut relative_responses = Vec::new();
|
||||||
for relative_item_val in relative_arr {
|
for relative_item_val in relative_arr {
|
||||||
if let Value::Object(mut relative_item) = relative_item_val {
|
if let Value::Object(mut relative_item) = relative_item_val {
|
||||||
if !relative_item.contains_key("organization_id") {
|
Self::inject_organization_id(&mut relative_item, &entity_fields, &item_schema);
|
||||||
if let Some(org_id) = entity_fields.get("organization_id") {
|
|
||||||
relative_item.insert("organization_id".to_string(), org_id.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Self::apply_entity_relation(
|
Self::apply_entity_relation(
|
||||||
&mut relative_item,
|
&mut relative_item,
|
||||||
@ -417,19 +435,8 @@ impl Merger {
|
|||||||
&entity_fields,
|
&entity_fields,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut item_schema = rel_schema.clone();
|
|
||||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) =
|
|
||||||
&rel_schema.obj.type_
|
|
||||||
{
|
|
||||||
if t == "array" {
|
|
||||||
if let Some(items_def) = &rel_schema.obj.items {
|
|
||||||
item_schema = items_def.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let merged_relative = match self.merge_internal(
|
let merged_relative = match self.merge_internal(
|
||||||
item_schema,
|
item_schema.clone(),
|
||||||
Value::Object(relative_item),
|
Value::Object(relative_item),
|
||||||
notifications,
|
notifications,
|
||||||
)? {
|
)? {
|
||||||
|
|||||||
Reference in New Issue
Block a user