I have three tables:
Table USER id name email
Table CAMPUS id user_id (foreign key) name
Table POST id title user_id (foreign key)
A User belongs to a Campus, and a Post belong to a User. I want to write a query to fetch posts inner join with user inner join with campus.
The result i get:
[{ id username campus name title ... }]
Everything is in a single object. Instead, I want nested objects like this:
[{ post_title: post_id: ... User: {id name... } campus:{id name ...} }]
This way, User and Campus are inherited in the post according to foreign keys. How can i achieve it with raw sql? Should I have to parse it later?