Giter Site home page Giter Site logo

Comments (6)

robsontenorio avatar robsontenorio commented on May 9, 2024 1

from vue-api-query.

robsontenorio avatar robsontenorio commented on May 9, 2024

You can create new instances manually. See on README.

let post = new Post()
post.id = 123

// or just pass as a payload

let post = new Post({id: 123})

// of course you can pass any other params

Then..

// GET /posts/123/comments
let comments = await post.comments().get()

Make sure Post and Comment extends from a BaseModel.

from vue-api-query.

Dylan-Chapman avatar Dylan-Chapman commented on May 9, 2024

Awesome, thanks! This method seems to work with get but not find as far as I can tell, though? So, modeling off of your example, I have:

const User = new User({id: 1})
const Post = await User.posts().find(2)

This fires "/posts/2" instead of "/users/1/posts/2".

from vue-api-query.

robsontenorio avatar robsontenorio commented on May 9, 2024

The find() method is suposed to be used with single resources.

For nested resources you should always use get().

As described on README you can use another methods before get() on nested resources.

await user.posts().where('id', 2).get()

from vue-api-query.

Dylan-Chapman avatar Dylan-Chapman commented on May 9, 2024

Okie dok. Is there some philosophy behind the find() method not being able to be used with nested resources? I thought nested resources with multiple identifiers was a common REST API pattern?

from vue-api-query.

robsontenorio avatar robsontenorio commented on May 9, 2024

@Dylan-Chapman Now you can do this

const User = new User({id: 1})
const Post = await User.posts().find(2)

Just upgrade to 1.1.0. Thanks @vjoao for PR!

from vue-api-query.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.