Skip to content

[BUG] supabase dataProvider getList uses invalid "foreignTable" option in .order() #6999

@adrzanbar

Description

@adrzanbar

Describe the bug

I was trying to sort by a joined table column and it was not working. A look into postgrest-js docs reveals the issue: order() method's arguments

https://supabase.github.io/postgrest-js/v2/classes/PostgrestTransformBuilder.html#order

sorters?.map((item) => {
        const [foreignTable, field] = item.field.split(/\.(?=[^.]+$)/);

        if (foreignTable && field) {
          query
            .select(meta?.select ?? `*, ${foreignTable}(${field})`) // why call select here AGAIN?
            .order(field, {                                         // should be `${foreignTable}(${field})'
              ascending: item.order === "asc",
              foreignTable: foreignTable,                           // this key does not exist
            });
        } else {
          query.order(item.field, {
            ascending: item.order === "asc",
          });
        }
      });

Steps To Reproduce

  1. Create a refine project with ant design and supabase, with examples.
  2. In blog-posts list, add a column with key=categories.name, dataIndex=["categories","name"] and sorter props.
  3. Click arrows to sort: nothing happens

Expected behavior

Get table with rows sorted by category name

Packages

  • @refinedev/supabase 6.0.0
  • @refinedev/antd 6.0.1
  • @supabase/supabase-js 2.7.0

Additional Context

How I got it to work

      sorters?.map((item) => {
        const [foreignTable, field] = item.field.split(/\.(?=[^.]+$)/);
        if (foreignTable && field) {
          query.order(`${foreignTable}(${field})`, {
            ascending: item.order === "asc",
          });
        } else {
          query.order(item.field, {
            ascending: item.order === "asc",
          });
        }
      });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions