Struggling to return partial data from multiple models connected via a "manyToMany" field and "through" relationship #8392
Unanswered
proffalken
asked this question in
Question & Answer
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I've built https://github.com/MakeMonmouth/mventory around this and it's awesome, but as I start to get more advanced I'm running in to issues.
In my models I want to link
Components
toSuppliers
. Due to the nature of theComponents
, eachComponent
may be sourced from multipleSuppliers
at different prices, and eachSupplier
can provide multipleComponents
.As a result, I've created a new model to link
Supplier
andComponent
, and now I want to display this in the API.The issue I have is that whilst I want this data to be shown as part of the call for a
Component
, I only want certain fields to be returned.The code I have so far is as follows:
This gives me the following output for a test component:
Ideally, I'd also want to include a link for each of the
Supplier
items to their specific view in the API, but I'm struggling to work out how I do this without returning all of the fields in theComponentSupplier
model (I don't want to disclose how much aComponent
is purchased for or what the markup might be, but I do want to disclose how much the membership price differs from the RRP for example).I'm reasonably sure that I need to follow the second example in this section of the docs, but I can't quite work out what the values should be in order to retrieve only the data about the Supplier currently being examined in the "main" loop.
Thanks in advance for any light you can shed on this!
Beta Was this translation helpful? Give feedback.
All reactions