Sails nested model associations and blueprint

45 views
Skip to first unread message

Pietro Passarelli

unread,
Feb 29, 2016, 3:25:33 PM2/29/16
to sails.js
Hello, 
I recently started using sails and I have a question regarding, Sails nested model associations and blueprint.

If i have a situation such as 
User->BlogPost->comments where
- a User has many BlogPost
- a BlogPost has many Comments 

And I want to set the model associations so that is a valid ORM association and the blueprint API can generate the corresponding API.

If I do 

user/:userId

I see the array of associated blogPosts

If I do 
user/:userId/post/:postId

I don't see the comments associated with that post 

And the following does not seem to be a valid route generated by the blueprint either

user/:userId/post/:postId/comment

But if I do 

post/:postId/comment

I see the array of comments associated with that BlogPost

Am I right in thinking that in order for the comments to show up at the routes through the use of blueprints I need to add something in the user model that sets a relationship between user and comment through BlogPost ?

user/:userId/post/:postId/comment

I am thinking like a has many through in rails.
But that doesn't require a join table just the "traversing" of an intermediate model.

I was wondering if anyone else has come across this issue and what (if any) possible solutions are there to keep this as simple as possible?

Best

Pietro


Reply all
Reply to author
Forward
0 new messages