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

Bugfix for providing item ID's to CRUDCollection list collection #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kieren
Copy link

@Kieren Kieren commented Sep 25, 2014

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.

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.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) when pulling 61e3f28 on Kieren:master into 2305f01 on cainus:master.

@cainus
Copy link
Owner

cainus commented Sep 27, 2014

Thanks! Any chance you can write a test for this scenario as well?

@hgarcia
Copy link

hgarcia commented Oct 16, 2014

+1, This also fixes a bug when passing listOptions with a key to the res.collections object.

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

Successfully merging this pull request may close these issues.

4 participants