plugin-axios icon indicating copy to clipboard operation
plugin-axios copied to clipboard

Response Entity with relationships (withAll())

Open crazymind opened this issue 6 years ago • 2 comments

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)
    })

crazymind avatar Oct 28 '19 09:10 crazymind

Yeah, I know. This will be solved if Vuex ORM manages to implement a "lazy load" feature, which is currently an active issue at Vuex ORM Core.

I'll keep the issue open as an enhancement, so we can keep tracking!

kiaking avatar Oct 29 '19 04:10 kiaking

@kiaking any updates on this?

xorinzor avatar Oct 30 '20 19:10 xorinzor