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

[5.3.9] Builded url for this.store.query incorrect when passing include as array #9588

Open
mkszepp opened this issue Nov 6, 2024 · 2 comments

Comments

@mkszepp
Copy link
Contributor

mkszepp commented Nov 6, 2024

The this.store.query (legacy adapters) isn't working correctly when we pass includes as array.

this.store.query<Company>('company', {
  filter: {
    type: 'example',
  },
  include: ['ceo', 'employee'],
});

The query params result in url is: &include[]=ceo&include[]=employee

it should be &include=ceo,employee

This bug was fixed for findAll & findRecord in #9583

It was not fixed for query (maybe also other) because this.buildQuery will not be called inside that function

query(store: Store, type: ModelSchema, query: Record<string, unknown>): Promise<AdapterPayload> {
const url = this.buildURL(type.modelName, null, null, 'query', query);
if (this.sortQueryParams) {
query = this.sortQueryParams(query);
}
return this.ajax(url, 'GET', { data: query });
}

@Techn1x
Copy link

Techn1x commented Feb 27, 2025

I have the same issue, where I need the query url formatted like &include=ceo,employee

Giving it as string for now so that it continues to work against the API as it is written, but then I need to ignore type issues.

@mkszepp
Copy link
Contributor Author

mkszepp commented Feb 27, 2025

@Techn1x just as tip... we have also initial hold as string in TS project, but removing all eslint disabled... were again so much work
At the end we have created a override in our apps in application adapter

// Fix for reported issue https://github.com/emberjs/data/issues/9588
  override query(store: Store, type: ModelSchema, query: Record<string, unknown>): Promise<AdapterPayload> {
    if (query) {
      const { include } = query;
      const normalizedInclude = Array.isArray(include) ? include.join(',') : include;

      if (normalizedInclude) {
        query['include'] = normalizedInclude;
      }
    }

    return super.query(store, type, query);
  }

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

No branches or pull requests

2 participants