You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
For update/delete operators, reference items in the collection by their id (instead of an object ref) #54
Ideally the collection should just follow the reference itself directly. So maybe instead the ref path is _ref_${collection.id} so if the collection can't find an object initially, it then looks for the _ref to follow.
Having to manually specify the ref is fairly painful — especially if you're passing in an array of items to update as you'd need to map over them to get the ref, etc. So automatic is much nicer.
changed the title [-]For query results, add references to the original collection object[/-][+]when mutating query results, automatically resolve the original collection's version of the object[/+]on May 12, 2025
I the best solution to this is to add the getId: (item) => item.id config option to all collections that's proposed in #79. Although I would advocate for calling it getKey or keyBy, that latter is an option in the query builder and has the same effect.
This lets the user decide on a collect-by-collection basis what their key is, this can then easily be accessible all the way through the query pipeline (with any joins, aggregates) without having to add any magic.
Although in the context of the electric collection, would we want to make it required? There is the foot gun of not setting it and not knowing the Electric constructs a key using the table name and PK - maybe the electric collection should automatically use the PK properly rather than the electric provided key that is very opaque?
The electric key is weird as it has to be universal. So requiring people to come up with their own is generally a more solvable issue. It gets tricky when the source table doesn't have an id. We'd also need to retain as the actual key the one provided by the server (or perhaps just ensure the users function doesn't provide duplicate IDs).
changed the title [-]when mutating query results, automatically resolve the original collection's version of the object[/-][+]For update/delete operators, reference items in the collection by their id (instead of an object ref)[/+]on May 28, 2025
Activity
KyleAMathews commentedon May 8, 2025
Ideally the collection should just follow the reference itself directly. So maybe instead the ref path is
_ref_${collection.id}so if the collection can't find an object initially, it then looks for the _ref to follow.Having to manually specify the ref is fairly painful — especially if you're passing in an array of items to update as you'd need to map over them to get the ref, etc. So automatic is much nicer.
KyleAMathews commentedon May 8, 2025
Good example of terrible things you have to do right now haha 50d38b6#diff-1809398801c87d5d881c6dbcec6a38033e6097410778035ad0378e0b21b07ca4R281
[-]For query results, add references to the original collection object[/-][+]when mutating query results, automatically resolve the original collection's version of the object[/+]samwillis commentedon May 23, 2025
Copying my comment from #106:
I the best solution to this is to add the
getId: (item) => item.idconfig option to all collections that's proposed in #79. Although I would advocate for calling itgetKeyorkeyBy, that latter is an option in the query builder and has the same effect.This lets the user decide on a collect-by-collection basis what their key is, this can then easily be accessible all the way through the query pipeline (with any joins, aggregates) without having to add any magic.
samwillis commentedon May 23, 2025
Although in the context of the electric collection, would we want to make it required? There is the foot gun of not setting it and not knowing the Electric constructs a key using the table name and PK - maybe the electric collection should automatically use the PK properly rather than the electric provided key that is very opaque?
KyleAMathews commentedon May 23, 2025
Hmm yeah so then it could be always id based e.g.
collection.update(queryItem.id, draft => draft.foo = true))That's explicit and pretty intuitive.
samwillis commentedon May 23, 2025
Exactly, and users are very used to the concept of keys / ids - there is nothing new here.
KyleAMathews commentedon May 23, 2025
The electric key is weird as it has to be universal. So requiring people to come up with their own is generally a more solvable issue. It gets tricky when the source table doesn't have an id. We'd also need to retain as the actual key the one provided by the server (or perhaps just ensure the users function doesn't provide duplicate IDs).
[-]when mutating query results, automatically resolve the original collection's version of the object[/-][+]For update/delete operators, reference items in the collection by their id (instead of an object ref)[/+]KyleAMathews commentedon May 28, 2025
Renamed the issue for the object id approach & assigned it to myself. I have a prototype going.