question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One-to-many link not consistently returning objects in the correct order

See original GitHub issue

Grapher appears to be inconsistent with how it treats the ordering of one-to-many links.

If I have a Post document like this:

const myPost = {
  commentIds: ['id1', 'id2'],
};

And a link between my Posts and Comments collection, I expect any grapher query to always return the 2 comments in the same order:

const myGrapherPost = {
  comments: [{ _id: 'id1', ...moreData1 }, { _id: 'id2', ...moreData2 }],
};

However I’ve started seeing some queries come back with a different order, like this:

const myGrapherPost = {
  comments: [{ _id: 'id2', ...moreData2 }, { _id: 'id1', ...moreData1 }],
};

It’s pretty hard to trace down, but I have this happening for 2 similar queries on the same collection, one with pure MongoDB data, and the other with an async Reducer fetching stuff from a third party API.

Is there a check somewhere that makes sure arrays are always ordered properly?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
theodorDiaconucommented, Aug 22, 2018

@Floriferous yes ofcourse, but like this:

Posts.createQuery({
   $options: { sort: { createdAt: -1 } },
   comments: {
        $options: { sort: { createdAt: -1 } },
   }
})
0reactions
Floriferouscommented, Aug 27, 2018

Is it possible that this nested $options can only go one level deep?

I’m getting an uncaught error: MinimongoError: Projection values should be one of 1, 0, true, or false when adding $options in one of my shared “fragments” across collections.

i.e. is something like this allowed ?:

Posts.createQuery({
   $options: { sort: { createdAt: -1 } },
   comments: {
        $options: { sort: { createdAt: -1 } },
        message: 1,
        linkedPosts: { // Link to Posts
          $options: { sort: { createdAt: -1 } } 
          comments: { message: 1, $options: { sort: { createdAt: -1 } } }
       }, 
   }
});

What else could be causing this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

hibernate OneToMany List ordering persisting but reversing?
I can completely re-order the java List in memory and when I save() the object the order of links in the linking table...
Read more >
ActiveObject OneToMany relationship returning an empty array
ActiveObject OneToMany relationship returning an empty array ... when I call getOrders(), it returns the correct objects from ComponentOrder.
Read more >
The best way to map a @OneToMany relationship with JPA ...
The @ManyToOne annotation allows you to map the Foreign Key column in the child entity mapping so that the child has an entity...
Read more >
Best Practices for Many-To-One and One ... - Thorben Janssen
Best Practices for Many-To-One and One-To-Many Association Mappings · 1 Don't use unidirectional one-to-many associations · 2 Avoid the mapping of huge to-many ......
Read more >
Relationship Loading Techniques
Eager loading refers to objects returned from a query with the related collection or scalar reference already loaded up front.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found