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

Fetching link and linkStorage in the same query returns inconsistent results #399

Closed
Floriferous opened this issue Nov 5, 2019 · 2 comments

Comments

@Floriferous
Copy link
Contributor

Floriferous commented Nov 5, 2019

When you fetch data with a link, and the linkStorage, it doesn't always return the right data based on the order of your fragment:

const A = new Mongo.Collection('a');
const B = new Mongo.Collection('b');

A.addLinks({
  bs: {
    field: 'bLinks',
    collection: B,
    type: 'many',
    unique: true
  }
});
B.addLinks({
  a: {
    collection: A,
    inversedBy: 'bs'
  }
});


describe('fetching links and their storage', () => {
  beforeEach(() => {
    A.remove({});
    B.remove({});
  });

  it('works', () => {
    A.insert({ _id: 'a1' });

    B.insert({ _id: 'b1', name: 'yoo' });
    B.getLink('b1', 'a').add('a1');

    const a1 = A.createQuery({
      $filters: { _id: 'a1' },
      bs: { name: 1 },
      bLinks: 1
    }).fetchOne();
    const a2 = A.createQuery({
      $filters: { _id: 'a12' },
      bLinks: 1,
      bs: { name: 1 }
    }).fetchOne();

    expect(a1).to.deep.equal(a2); // Fails
  });
});

I expect both queries to return the same data.

@vparpoil
Copy link
Contributor

vparpoil commented Nov 7, 2019

I think this is the same as #386. I have tried to fix in a PR but it's not yet finalized because the proposed fix may not work in all cases. I need to sit down and dive into grapher more to produce a better fix

@Floriferous
Copy link
Contributor Author

You’re right!

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