fix(DatabaseController): Do not match any entry when searching for null in relation field (#3924)

This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2017-06-21 09:23:20 -03:00
committed by Florent Vilmart
parent 4509d25471
commit a0d1a3517f
4 changed files with 220 additions and 33 deletions

View File

@@ -188,7 +188,7 @@ const buildWhereClause = ({ schema, query, index }) => {
// nothingin the schema, it's gonna blow up
if (!schema.fields[fieldName]) {
// as it won't exist
if (fieldValue.$exists === false) {
if (fieldValue && fieldValue.$exists === false) {
continue;
}
}
@@ -202,7 +202,16 @@ const buildWhereClause = ({ schema, query, index }) => {
});
let name = components.slice(0, components.length - 1).join('->');
name += '->>' + components[components.length - 1];
patterns.push(`${name} = '${fieldValue}'`);
if (fieldValue === null) {
patterns.push(`${name} IS NULL`);
} else {
patterns.push(`${name} = '${fieldValue}'`);
}
} else if (fieldValue === null) {
patterns.push(`$${index}:name IS NULL`);
values.push(fieldName);
index += 1;
continue;
} else if (typeof fieldValue === 'string') {
patterns.push(`$${index}:name = $${index + 1}`);
values.push(fieldName, fieldValue);
@@ -231,13 +240,16 @@ const buildWhereClause = ({ schema, query, index }) => {
values.push(...clauseValues);
}
if (fieldValue.$ne) {
if (fieldValue.$ne !== undefined) {
if (isArrayField) {
fieldValue.$ne = JSON.stringify([fieldValue.$ne]);
patterns.push(`NOT array_contains($${index}:name, $${index + 1})`);
} else {
if (fieldValue.$ne === null) {
patterns.push(`$${index}:name <> $${index + 1}`);
patterns.push(`$${index}:name IS NOT NULL`);
values.push(fieldName);
index += 1;
continue;
} else {
// if not null, we need to manually exclude null
patterns.push(`($${index}:name <> $${index + 1} OR $${index}:name IS NULL)`);
@@ -764,6 +776,9 @@ export class PostgresStorageAdapter {
validateKeys(object);
Object.keys(object).forEach(fieldName => {
if (object[fieldName] === null) {
return;
}
var authDataMatch = fieldName.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
if (authDataMatch) {
var provider = authDataMatch[1];