Comments (6)
In case anyone's curious, a potential solution in the schema file:
field :tags, {:array, :map}, virtual: true
def inject_tags_from_tag_ids(product) do
tag_ids = product.tag_ids || []
tags = for id <- tag_ids, do: %{id: id}
%{product | tags: tags}
end
Then adding tags: TagView
to relationships
in the View seems to work OK, as long as you pass your product
through the function at some point.
NOTE: edited to remove incorrect :include
from View code example.
from jsonapi.
from jsonapi.
Just spitballing on things that would've seemed easier to me.
here's one idea:
def relationships do
[
# other entries...
tags: {:tag_ids, &tags_from_ids/1}
]
end
defp tags_from_ids(tag_ids) do
for id <- tag_ids, do: %{id: id, type: "tags"}
end
The idea being that :tag_ids
is the name of the field that is the source of the data, and &tags_from_ids/1
is the function to transform said data.
The particulars above could be modified to allow specifying TagView
somewhere as well, etc. If that's easier.
from jsonapi.
You could also lock it down more with
def relationships do
[
# other entries...
tags: [ids: :tag_ids, type: "tags"]
]
end
That's less flexible, intended only for an input that is known to be a list of IDs (as is true for us). I'm not sure what else you might be getting in for a relationship, anyway.
from jsonapi.
FYI, this is no longer a priority for our specific project.
from jsonapi.
Ha! I was just contemplating this issue. Many thanks for the heads up. I'll close this issue then.
from jsonapi.
Related Issues (20)
- UnderscoreParameters behaviour with GET requests HOT 6
- Migrating to BEAM Community org HOT 15
- Bug with expected format in `included` data HOT 2
- Add GitHub Actions workflow for Hex package releases HOT 3
- Extensions and `lid` HOT 1
- Dynamic fields in views HOT 3
- Publish New Version on Hex HOT 3
- Empty one-to-one relationship incorrectly surfaced (should be surfaced as null) HOT 5
- The url_for_pagination function throws an error when supplied a nested filter HOT 1
- Replace query params as default HOT 1
- Standardize on underscoring query parameters HOT 2
- (FunctionClauseError) no function clause matching in JSONAPI.Utils.DataToParams.transform_relationship/2 HOT 3
- [Feature] Allow For Exclusion of Optional Resource Members HOT 5
- Allow conditionally hidden fields HOT 2
- Bug: Relationship keys not transformed with `dasherize_shallow` config option
- Incorrect InvalidQuery Errors Caused by `String.to_existing_atom/1` HOT 2
- Paginating Relationships HOT 1
- Assertion for tests HOT 1
- JSONAPI.ContentTypeNegotiation ignore some methods for validation HOT 4
- Serializer incorrectly re-orders lists
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi.