Skip to content

Releases: vuex-orm/vuex-orm

v0.11.5

23 Nov 05:37
Compare
Choose a tag to compare

Fixes

  • #21 Returns empty array instead of null when fetching multiple records.

v0.11.4

18 Nov 13:28
Compare
Choose a tag to compare

Fix

  • #20 Fix first method not respecting orderBy.

v0.11.3

17 Nov 06:08
Compare
Choose a tag to compare

Fix

  • Fix where first method fetching initial record when null is passed as an argument

v0.11.2

08 Nov 13:40
Compare
Choose a tag to compare

Nested object schema

Now it's able to define nested object schema at model.

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      id: this.attr(null),
      name: this.attr(''),
      settings: {
        type: this.attr(0),
        profile: this.hasOne(Profile, 'user_id')
      }
    }
  }
}

v0.11.1

06 Nov 08:33
Compare
Choose a tag to compare

Local variables in where closure

Now you can use local variable in where closure!

const ageAsVariable = 40

const result = Repo.query(state, 'users', false)
  .where(r => r.age < ageAsVariable)
  .get()

Thanks to @Arjeno for this awesome fix!

v0.11.0

29 Oct 14:53
Compare
Choose a tag to compare

Update feature

Now it's possible to use update action. See here for the detail.

Delete feature

#11 Now you can delete record from the store with delete action. See here for the detail.

v0.10.0

27 Oct 07:36
Compare
Choose a tag to compare

Breaking Changes

TO reduce bundle size, moment was removed from dependency. Due to this, this.date method was also removed. Instead you can now specify more generic mutators.

New Mutators

You can now use following feature to mutate any data.

Via Attribute

You can pass a closure to the 2nd argument of attr method. The closure takes the corresponding value as an argument, and you can modify the value however you want.

import { Model } from 'vuex-orm'

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      id: this.attr(null),
      name: this.attr('', value => value.toUpperCase())
    }
  }
}

const user = new User({ name: 'john doe' })

user.name

// JOHN DOE

Vie Mutators Method

You can also define mutators in one place by creating static mutators method. The mutators method should return an object containing a function with the key of the corresponding field.

import { Model } from 'vuex-orm'

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      name: this.attr('')
    }
  }

  static mutators () {
    return {
      name (value) {
        return value.toUpperCase()
      }
    }
  }
}

const user = new User({ name: 'john doe' })

user.name

// JOHN DOE

Note that if you have mutator defined at the 2nd argument of the attr, and also have mutators method with the same field name, the mutator at attr takes the president.

v0.9.0

27 Oct 05:15
Compare
Choose a tag to compare

Introduce module bundles

Now Vuex ORM generates bundled js files in UMD, CommonJS, and ES format.

Breaking Changes

Import Path

Due to bundling system, you must now change how you import modules from Vuex ORM. Before the modules needed to be imported from under lib directory but from this release, it should be imported using { Database } syntax.

// Before
import Database from 'vuex-orm/lib/Database'
import Model from 'vuex-orm/lib/Model'

// After
import { Database } from 'vuex-orm'
import { Model } from 'vuex-orm'

Plugin Installation Method

Also due to the bundling system, you must call install method when registering Vuex ORM as a plugin to the Vuex.

import VuexORM from 'vuex-orm'

store = new Vuex.Store({
  plugin: [VuexORM.install(database)]
})

Fixes

  • #8 Tree shaken lodash module to decrease the bundle size.

v0.8.1

21 Oct 16:37
Compare
Choose a tag to compare

Fix

  • Do not set foreign key when creating data if the data already has one.

v0.8.0

21 Oct 15:07
Compare
Choose a tag to compare

Load Nested Relation

You can load nested relation with dot syntax.

const user = store.getters['entities/users/query']().with('posts.comments').first(1)

/*
  User {
    id: 1,
    name: 'john',

    posts: [
      Post: {
        id: 1,
        user_id: 1,
        body: '...',

        comments: [
          Comment: { id: 1, post_id: 1, body: '...' },
          Comment: { id: 2, post_id: 1, body: '...' }
        ]
      },

      Post: {
        id: 2,
        user_id: 1,
        body: '...',

        comments: [
          Comment: { id: 3, post_id: 2, body: '...' },
          Comment: { id: 4, post_id: 2, body: '...' }
        ]
      },
    ]
  }
*/

Relation Constraint

To filter the result of relation loaded with with method, you can do so by passing closure to the second argument.

const user = store.getters['entities/users/query']().with('posts', (query) => {
  query.where('published', true)
}).first(1)

/*
  User {
    id: 1,
    name: 'john',

    posts: [
      Post: { id: 1, user_id: 1, body: '...', published: true },
      Post: { id: 2, user_id: 1, body: '...', published: true }
    ]
  }
*/

When you want to add constraint to the nested relation, use closure instead of dot syntax.

const user = store.getters['entities/users/query']().with('posts', (query) => {
  query.with('comments', (query) => {
    query.where('type', 'review')
  }).where('published', true)
}).first(1)

/*
  User {
    id: 1,
    name: 'john',

    posts: [
      Post: {
        id: 1,
        user_id: 1,
        body: '...',
        published: true,

        comments: [
          Comment: { id: 1, post_id: 1, body: '...', type: 'review' },
          Comment: { id: 2, post_id: 1, body: '...', type: 'review' }
        ]
      },

      Post: {
        id: 2,
        user_id: 1,
        body: '...',
        published: true,

        comments: [
          Comment: { id: 3, post_id: 2, body: '...', type: 'review' },
          Comment: { id: 4, post_id: 2, body: '...', type: 'review' }
        ]
      },
    ]
  }
*/