Skip to content

Response Entity with relationships (withAll()) #78

Open
@crazymind

Description

@crazymind

Let's take this model as example:

 export default class Transfer extends Model {
  static entity = 'transfers'

  static fields () {
    return {
      id: this.attr(null),
      files: this.hasMany(File, 'transfer_id'),
      links: this.hasMany(Link, 'transfer_id'),
    }
  }

Currently we receive the entities all separated. But it would be nice if the requested model would also had the objects included (like if you would execute query().withAll())

return Transfer.api().get(`/transfers/${transferId}`)
    .then((response) => {

      console.log(response.entities.transfers)
      console.log(response.entities.files)
      console.log(response.entities.links)
     
      // Have to query to this way to get files
      let transfer = Transfer.query()
        .withAll()
        .where({
          id: response.entities.transfers[0]
        })
        .first();
     
      commit('doSomething', transfer)
    })

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions