feat(smart views): smart views can access nested relationship#203
feat(smart views): smart views can access nested relationship#203VincentMolinie wants to merge 2 commits intomainfrom
Conversation
|
To add more context about how JSON API works: |
| "inflected": "2.0.4", | ||
| "ip-utils": "git+https://github.com/ForestAdmin/ip-utils.git#5f88562ba53fedcdc0374937fca0fdb71fa4923c", | ||
| "jsonapi-serializer": "3.4.1", | ||
| "jsonapi-serializer": "3.6.1", |
There was a problem hiding this comment.
This fix some issue with the serializer and allow to return null from relationshipLinks function and not include the link in this case
| function getAttributesFor(dest, fields) { | ||
| function getRelatedLinkForHasMany(modelName, relationshipName) { | ||
| return function (record, current, parent) { | ||
| if (current && current[relationshipName]) { |
There was a problem hiding this comment.
We do not want the link to be set if the relation is already included in the payload
| : getRelatedLinkForHasMany(modelName, field.field); | ||
| dest[fieldName] = { | ||
| ref: fieldReference, | ||
| nullIfMissing: true, |
There was a problem hiding this comment.
We need this or the links will not be included if the relation is not in the records sent to the serializer
| if (_.isArray(field.type)) { | ||
| dest[fieldName].ignoreRelationshipData = true; | ||
| if (_.isArray(field.type) || !include) { | ||
| dest[fieldName].ignoreRelationshipData = include; |
There was a problem hiding this comment.
We do not include from second level (We never include relations of a relation)
| } | ||
|
|
||
| var serializationOptions = { | ||
| function defineRelationshipId(records, fields, goDeeper = true) { |
There was a problem hiding this comment.
Recursive function to initialize belongsTo with an id if not set (based on foreignKey) so the serializer can return the { data: { id: 2 } }
| const fieldName = field.field; | ||
| const [referenceType,referenceKey] = field.reference.split('.'); | ||
| const referenceSchema = Schemas.schemas[referenceType]; | ||
| if (goDeeper && record[fieldName]) { |
There was a problem hiding this comment.
We only do it on one level. But we could do it recursively like on forest-rails (@arnaudbesnier Your call)
|
Let's keep this for later. We need stability now and I don't want to introduce unecessary feature. Especially on the liana side. |
3944c3b to
077553b
Compare
12de3c3 to
33e1a19
Compare
rap2hpoutre
left a comment
There was a problem hiding this comment.
Thank you for this contribution! Since this repository now uses (experimental) semantic release, you might have to:
- Remove entry to changelog.
- Change the target to master.
- Change the title (you could
fix(smart views): smart views can access nested relationship).
Let me know if I can help!
b4141a8 to
55fd940
Compare
|
Code Climate has analyzed commit 9ece720 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 78.3% (70% is the threshold). This pull request will bring the total coverage in the repository to 60.6% (0.6% change). View more on Code Climate. |
Description
The purpose of this PR is to return correctly all relationships from the liana. This will allow to use simple getters on Smart View.
Requirements
https://github.com/ForestAdmin/forestadmin/pull/1022
Pull Request checklist: