Returning related data in api query
Hi, I'm trying to get all my subscriptions and return all the orders linked to that subscription record.
I believe I have the schema setup correctly and have the syntax for the query correclty, but all it does is return the ID and not the entire record. If I write out the "select" in it's entirety for each column, I get a lint error. Attached some images of the schemas and the query that's not returning what' I'd like. Also attached is the result of the console log for the
subscriptionsWithAllOrders
query.
I'm hoping maybe I can just do a join
of some kind in my findMany
method, but no luck and not seeing any documentation on how to do this.
Thanks



11 Replies
Hello,
rechargeSubscriptionId
is only the id of the record. You need to use something like this:
@Chocci_Milk Thanks Antoine. Do you have a link to the documentation on this? That seems to be the correct way, but I need these to join on a specific column.
Say this is the flow.
- I get the rechargeOrder like it shows in my image attached
- The rechargeOrder has a column rechargeSubscription.
- rechargeSubscription has a column named rechargeSubscriptionId (different from what the autogenerated PK gives)
- I think I need to modify my approach because currently if I do it how I have it, the rechargeSubscription comes back as null
the console log returns this:
I can assure you that the values relate between the two tables.
I have the type setup where the rechargeOrder belongs to one rechargeSubscription and that rechargeSubscription has man rechargeOrders
For more information on relationships and your specific API, you can take a look at the API references and the specific schema for the model you're trying to fetch
I've looked over the documentation and I was hoping that maybe there was a link to something that had more complicated examples. Is there no documentation for that?
We don't have many examples of related model filtering. If you explain exactly what you're trying to do and what models you need, I can probably give you a short snippet
The internal docs do have some more examples. That's good to know. However, it still doesn't completely help. The query above should work. Here's the schemas and data to prove so.
Again, the console log is returning this
did I set up the schema incorrectly?




when I create the record, I do link it

If im understanding the relationship intended for the Schema, the
Order
is the Parent and Subscription
is the users within the plan?
I can take a better look if you can share the app URL
Im looking at the query, would you be able to share what its for?
I dont immidiately see any issues that would cause the results not to show but II do see that rechargeOrderId is a string
not number
the
Subscription
is the parent and has many Order
https://clingy.gadget.app/
The rechargeOrderId is a number on the recahrgeOrder
model. Would that be it? Do relations have to be strings?I checked the docs in your app and this is how you could write a
rechargeOrder
query
If I understand the relationships correct this should be correctThank you, I'll give a try
I went to try this and this is what I currently have implemented and it's not working
You might be able to confirm this. But would it be because of a tenancy issue? These values get injected via a CRON job in my global actions.