moderate-tomatoM
Refine10mo ago
8 replies
moderate-tomato

Supabase column filter and !inner in query

I have some join tables in my supabase database let say "devices" and "locations" defined like this :
devices {
  id : bigint,
  name: text,
  assigned: bool,
  location_id : bigint
}

locations {
  id : bigint,
  name: text,
}


with a foreign key location_id in devices pointing to locations. This foreign key is defined only is the assigned flag is true.

I'm using refine useTable component defined as this :
const {tableProps} = useTable(
resource: "devices",
meta: {
      select:
        "*, locations(id, name)",
    },

and my page defined like this :
<Table {...tableProps}>
  <Table.Column
    dataIndex="name"
    title={"Name"}
    defaultSortOrder={getDefaultSortOrder("name", sorters)}
    sorter
  />
  <Table.Column
    dataIndex="location_id"
    title={"Location"}
    filteredValue={getDefaultFilter("location_id", filters, "in")}
    render={(_value, record: IDevice, _index) => {
      return <>{record.locations?.name}</>;
    }}
    filterDropdown={(props) => (
      <FilterDropdown
        {...props}
        mapValue={(selectedKeys) => {
          return selectedKeys.map((i) => parseInt(i.toString()));
        }}
      >
        <Select
          style={{ minWidth: 150 }}
          mode="multiple"
          {...locationsSelectProps}
          placeholder={t("list.searchByLocation")}
        />
      </FilterDropdown>
    )}
      />
</Table>


The problem is when I use the location filter, it doesn't filter the device record until I make my useTable select as "*, locations!inner(id, name)" but then if I'm doing that, I won't see anymore devices with no location_id and assigned flag to false.
Is there a way to manage that easily or I need to manage filter manually by myself inside the filter property of useTable ?
Was this page helpful?