Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
fix: $select for many to one navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Soontao committed Oct 11, 2020
1 parent 8d71700 commit cc02c22
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/processor/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ export class ODataProcessor extends Transform {
if (part.key) {
part.key.forEach((key) => params[key.name] = key.value);
}
navigationResult = await this.__read(ctrl, part, params, result, foreignFilter, navigationType, include, select);
navigationResult = await this.__read(ctrl, part, params, result, foreignFilter, navigationType, include, include.select);
} else {
const foreignKeys = Edm.getForeignKeys(elementType, include.navigationProperty);
const part: any = {};
Expand All @@ -1801,7 +1801,7 @@ export class ODataProcessor extends Transform {
if (nav?.type == 'OneToOne' && !isEmpty(nav.targetForeignKey)) {
const [keyName] = Edm.getKeyProperties(elementType);
const foreignFilter = ODataFilter.New().field(nav.targetForeignKey).eq(result[keyName]).toString();
navigationResult = await this.__read(ctrl, part, params, result, foreignFilter, navigationType, include, select);
navigationResult = await this.__read(ctrl, part, params, result, foreignFilter, navigationType, include, include.select);

const data = get(navigationResult, '_originalResult.value[0]');

Expand All @@ -1822,7 +1822,7 @@ export class ODataProcessor extends Transform {
if (part.key) {
part.key.forEach((key) => params[key.name] = key.value);
}
navigationResult = await this.__read(ctrl, part, params, result, undefined, navigationType, include, select);
navigationResult = await this.__read(ctrl, part, params, result, undefined, navigationType, include, include.select);

}

Expand Down
19 changes: 19 additions & 0 deletions test/type/server_query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('server query result Test Suite', () => {
});

it('should support $select parameter', async () => {

@ODataModel()
class SelectModel {
@UUIDKeyProperty() key: string;
Expand Down Expand Up @@ -126,6 +127,8 @@ describe('server query result Test Suite', () => {

try {
const selectModels = client.getEntitySet<SelectModel>('SelectModels');
const selectRefModels = client.getEntitySet<SelectRefModel>('SelectRefModels');

const createdItem = await selectModels.create({
f1: 'v1',
f2: 'v2',
Expand Down Expand Up @@ -172,6 +175,22 @@ describe('server query result Test Suite', () => {
expect(onlyF1ExpandedRF1Objects[0].refs[0]).toHaveProperty('rf1');
expect(onlyF1ExpandedRF1Objects[0].refs[0]).not.toHaveProperty('rf2');
expect(onlyF1ExpandedRF1Objects[0].refs[0]).not.toHaveProperty('rf3');
const [{ key }] = await selectRefModels.query();

const r4 = await selectRefModels.retrieve(
key,
client.newParam().expand('sm($select=f1)').select('rf1')
);

expect(r4).toHaveProperty('rf1');
expect(r4).toHaveProperty('sm');
expect(r4).not.toHaveProperty('rf2');
expect(r4).not.toHaveProperty('rf2');

expect(r4.sm).toHaveProperty('f1');
expect(r4.sm).not.toHaveProperty('f2');
expect(r4.sm).not.toHaveProperty('f3');


} finally {
await shutdownServer();
Expand Down

0 comments on commit cc02c22

Please sign in to comment.