aarondfrancis / vue-model

Model component for Vue.js
MIT License
857 stars 42 forks source link

Nested resources #13

Closed JonasDoebertin closed 7 years ago

JonasDoebertin commented 7 years ago

Right now, it's quite hard to use this for nested resources.

Imagine this routes setup:

GET /posts/{post-id}/comments POST /posts/{post-id}/comments PUT /posts/{post-id}/comments/{comment-id}

Do you have plans to accommodate for this (however the solution may look)?

aarondfrancis commented 7 years ago

I think you can do that if you have a Comment model and it has a post_id in it. Then you'd just set your base route on the comment model /posts/{post_id}/comments.

The interpolate function will replace anything in {} with the value in your model: https://github.com/aarondfrancis/vue-model/blob/master/src/Model.js#L320

Let me know if that helps!

JonasDoebertin commented 7 years ago

Thanks a lot! Works just fine:

{
    baseRoute: '/api/posts/{post_id}/comments',
    actions: {
        create: {
            method: 'POST',
            route: '',
            pipeline: function(DataPipeline) {
                DataPipeline.without('post_id');
            }
        }
    }
}