Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for empty arrays in Hasura

I have the following Query:

query {
  table1(where: {table2: {id: {}}}) {
    id
  }
}

There is a relationship between table1 and table2 via a foreign key. That is, in table2 I have a column named table1_id and so I can access table2 from table1. I want to query all rows from table1 that have no related rows in table2. That is, if I do the following query:

query {
  table1 {
    table2 {
      id
    }
  }
}

I want the rows in table1 where this query returns an empty array. I have tried the following:

query {
  table1(where: {table2: {id: {_in: []}}}) {
    id
  }
}

And

query {
  table1(where: {table2: {id: {_is_null: true}}}) {
    id
  }
}

But nothing seems to work (I get back an empty array). What am I doing wrong?

like image 754
davidaap Avatar asked Jul 11 '20 16:07

davidaap


Video Answer


1 Answers

query {
  table1(where: {_not: { table2: {} } }) {
    id
  }
}

Should work to return the records from table1 that don't have a relationship with table2

like image 130
Leonardo Alves Avatar answered Oct 06 '22 08:10

Leonardo Alves