added limit 1 to arrays treated as a single value in schemas
This commit is contained in:
@ -240,7 +240,7 @@ impl<'a> Compiler<'a> {
|
||||
};
|
||||
|
||||
// 3. Build WHERE clauses
|
||||
let where_clauses = self.compile_where_clause(r#type, &table_aliases, node)?;
|
||||
let where_clauses = self.compile_where_clause(r#type, &table_aliases, node.clone())?;
|
||||
|
||||
let selection = if is_array {
|
||||
format!("COALESCE(jsonb_agg({}), '[]'::jsonb)", jsonb_obj_sql)
|
||||
@ -248,11 +248,38 @@ impl<'a> Compiler<'a> {
|
||||
jsonb_obj_sql
|
||||
};
|
||||
|
||||
let mut limit_clause = "";
|
||||
if !is_array {
|
||||
let is_reverse = if let Some(prop_ref) = &node.property_name {
|
||||
let prop = prop_ref.as_str();
|
||||
if let Some(parent_schema) = &node.parent_schema {
|
||||
if let Some(compiled_edges) = parent_schema.obj.compiled_edges.get() {
|
||||
if let Some(edge) = compiled_edges.get(prop) {
|
||||
!edge.forward
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if is_reverse {
|
||||
limit_clause = " LIMIT 1";
|
||||
}
|
||||
}
|
||||
|
||||
let full_sql = format!(
|
||||
"(SELECT {} FROM {} WHERE {})",
|
||||
"(SELECT {} FROM {} WHERE {}{})",
|
||||
selection,
|
||||
from_clauses.join(" "),
|
||||
where_clauses.join(" AND ")
|
||||
where_clauses.join(" AND "),
|
||||
limit_clause
|
||||
);
|
||||
|
||||
Ok((
|
||||
|
||||
Reference in New Issue
Block a user