Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto select primary keys if select prop was provided #960

Open
samislam opened this issue Aug 23, 2024 · 1 comment
Open

auto select primary keys if select prop was provided #960

samislam opened this issue Aug 23, 2024 · 1 comment

Comments

@samislam
Copy link

Based on the documentation, if you want to enable the select feature through the URL query (localhost?select=...), you have to ensure doing two things:
First you must add the select property into the paginate() function call:

paginate(query, repo, {
   sortableColumns: / ** /,
   select: /* this needs to be set*/, // 👈
})

Second
You need to ensure that in the select option, you're selecting the primary key, for example id:

paginate(query, repo, {
   sortableColumns: / ** /,
   select: ["id" 👈 , /* and optionally any other column */],
})

My suggestion is, instead of making it that way, let's make the library itself add the primary key internally, because without that, if someone requests:

localhost?select=username

It's not going to work and it will return every other column, which makes someone think that there is a bug.

My suggestion is that the library should handle it internally somehow like this:

const repoPrimaryKey = /* the logic to get the repository primary key */
const selectedColumns = new Set()
if(select !== undefined && Array.isArray(select)) {
  selectedColumns.forEach(columnName = selectedColumns.add(columnName))
  selectedColumns.add(repoPrimaryKey)
}
const isSelectEnabled = !!selectedColumns.length
// ... rest
@ppetzold
Copy link
Owner

happy to merge if you find a solution. as far as I remember the mandatory PK + client select being a subset of a mandatory server side set, were more like cheap fixes while we struggled to make a cleaner version work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants