This repository was archived by the owner on Apr 22, 2021. It is now read-only.
Closed
Conversation
Create tests for "Includes JSON"
Create tests for "Includes JSON"
Option 'merge: true' is not needed
Contributor
|
Thank you! Sorry for the delay, will be reviewing this shortly. |
Contributor
Author
|
I have just noticed that this feature is an extended version of (#61) recently pull request accepted. |
Conflicts: supermodel.js supermodel.min.js
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Hi again!
As I stated early this week (#66), I want to share with you some modifications to Supermodel library which I miss on working in my day to day.
This time I bring you Jsonify options which will be very useful when serializing models to persist or use in templates.
PD: This branch includes some corrections and test fixing I made for newer versions of Backbone.js. I made a pull request formerly. (#65)
Jsonify
We sometimes need that relationships defined among models are also parsed when running "toJSON" function. Thus, I have brought to you the possibility to configure which relationships you want to be serialized. Further, you are also enabled to configure which attributes or associations to include or exclude in the "toJSON" method output.
Global configuration
You may set up a default behaviour to the "toJSON" function.
defaultInJson
Boolean. Set to true to serialize all associations by default when jsonify.
cidInJson
Boolean. A value of true includes cid attribute in json output.
Example
Local configuration
You may have the neccesity to configure serialization specifically. To do so, you are enable to do it by function parameter, model and association level. If a local configuration does not include some association, the default value defined in the global configuration will be used.
Configuration by parameter
"toJSON" function has been altered to accept options to control output and relationship serialization. This configuration method could be very useful to distingish serialization for persisting or templating processes.
The options that are able to be passed to model.toJSON([options]) are described below:
includeInJson
String or String[]. Returns the object which represents the model but only picks the provided attribute/s and relation/s.
excludeInJson
String or String[]. Returns the object which represents the model but omits the provided attribute/s and association/s.
assocInJson
Object representing:
{associationName : configuration}
Configuration may accept a boolean, a string or an array referencing a model's attribute/s or association/s, or an object.
Example
Configuration by model
When you are defining models, you may set up the serialize configuration as well.
Example
Configuration by association
You may set up the serialize configuration when you are defining associations.
Example