Bugfix for providing item ID's to CRUDCollection list collection#94
Open
Kieren wants to merge 2 commits intocainus:masterfrom
Open
Bugfix for providing item ID's to CRUDCollection list collection#94Kieren wants to merge 2 commits intocainus:masterfrom
Kieren wants to merge 2 commits intocainus:masterfrom
Conversation
outputList function accepts an (optional) options object with a single "key" property, currently this option is used to switch the collection list from and array of items to an object with the list items as keyed properties - the value of the "key" property is used to select the key values to be used as property names. However the current implementation incorrectly passes the whole listOptions object to the HyperJsonCollection (collection) function instead of just passing listOptions.key, so this feature has a bug. Additionally the listOptions.key property is later used to supply the items ID attribute name to the autoLink functionality provided by CRUDCollection. These two separate uses for the same option while similar are potentially independent, consider trying to output a list of items as an array while providing the autoLink functionality with the correct item id to generate a working _self hyperlink. This patch provides for a second option object property, "listAsKeyedObject" which is truthily tested to allow for all possible use cases to be defined by listOptions. The default behaviour of listOptions (when not supplied) is maintained with original, however the buggy behaviour of listOptions.key usage has been fixed and adjusted, so listOptions.listAsKeyedObject must be truthy for CRUDCollection to generate the items list as an object using item[listOptions.key] values as property names for each item.
Added check for listOptions.key existence to autoLink generating code.
Owner
|
Thanks! Any chance you can write a test for this scenario as well? |
|
+1, This also fixes a bug when passing listOptions with a key to the res.collections object. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch allows listOptions.key to be provided to CRUDCollections list() function without it generating buggy output. New option listOptions.listAsKeyedObject enables listOptions.key to be optionally passed to HyperJsonCollection collection() function, switching output from an array of items to an object with items as property values and item[listOptions.key] property names. Autolink works as normal with the optional listOptions.key property.