Skip to content
Compare
Choose a tag to compare

BREAKING CHANGES

  • As of this release, Vuex ORM no longer exposes internals in @vuex-orm/core/lib. Types should now be imported from @vuex-orm/core/dist/src.

Bug Fixes

  • database: improve performance with entity lookup (#718) (8b5f104)
  • withAll should observe constraints (f3fdf02)
Compare
Choose a tag to compare

Fixes

  • #455 $update function not working with a composite primary key.
  • #596 Fix persist methods failing to create an array of records in the Nuxt server-side environment.

Improvements

  • #590 Add support for composite primary keys in whereId and whereIdIn clause.
Compare
Choose a tag to compare

Fixes

  • #516 Preserve original data when passing it to persistent methods.
  • #571 Fix Many-to-many relations orderBy constraint does not resolve correctly.
  • #588 Fix findIn not resolving child relations.

Improvements

  • #553 Update Nprmalizr to the latest version.
Compare
Choose a tag to compare

Fixes

  • #544 #548 Fix where model retrieving was not working correctly on SSR environment such as Nuxt.js.
Compare
Choose a tag to compare

New Features

Access intermediate model through relationships.

Issue: #527

You may now access the intermediate model through customizable pivot attribute on the relationships.

class User extends Model {
  static entity = 'users'static fields () {
    return {
      id: this.attr(null),
      podcasts: this.belongsToMany(
        Podcast,
        Subscription,
        'user_id',
        'podcast_id'
      ).as('subscription')
    }
  }
}const user = User.query().with('podcasts').first()user.podcasts.forEach((podcast) => {
  // Access to pivot model!
  console.log(podcast.subscription)
})

Please refer to the documentation for more details.

New exists method available in query chain.

Isseu: #486

The exists method allows you to check wether a query chain would return any records. The method will return either true or false.

// Check whether the user store contains any data.
const resultExists = User.exists()

// Check whether an user with id 5 exists.
const resultExists = User.query().where('id', 5).exists()

Expose Database object to the plugin components

Issue: #557

Now Database object is also passed to the plugin component options.

It adds as method to many-to-many relationship attribute to let users customize pivot key name.

Compare
Choose a tag to compare

Fixes

  • #546 Fixed incomprehensible exception thrown due to missing var name.
  • #549 Fixed orderBy order of numbers was not correct.
Compare
Choose a tag to compare

Improvements

  • #543 Add warning when using deprecated increment attribute.

Thanks to @cuebit for the wonderful PR! 🎉

Compare
Choose a tag to compare

New Features

Context based model access.

You can get model objects through store instance. Please refer to issue #514 for the reason why we needed this.

Now you can access models like this.

// String base access.
const User = store.$db.model('users')

// Type base access.
import User from '@/models/User'

const UserModel = store.$db.model(User)

To be able to add this feature, there're few internal breaking changes. It shouldn't affect most of the users.

  • The Query now must receive database instance as the first argument.
  • The Query's get methods such as getModel are now an instance method.
  • The Container now holds store instance instead of a database.

Please refer to the documentation for more details.

Register models at runtime.

Issue #187

Now you can register a new model after you've installed Vuex ORM to Vuex. All you need to do is to call database.register.

Thanks to @SzNagyMisu for this wonderful PR! 🎉

Fixes

  • #513 Make Model.fields().attribute.value correctly typed.
  • #526 Exclude $id from toJson() method.
  • #536 Now the pivot table composite key can be in any order.
Compare
Choose a tag to compare

Improvements

Passing a function to the 1st argument of orderBy method.

Now you can pass a function as the 1st argument of orderBy. The function will accept a record that is being sorted, and it should return value to be sorted by.

// Sort user name by its 3rd character.
const users = User.query().orderBy(user => user.name[2]).get()

/*
  [
    { id: 4, name: 'Andy' },
    { id: 2, name: 'Roger' },
    { id: 1, name: 'John' }
  ]
*/

Thanks to @leearaneta for this wonderful PR! 🎉

Fixes

  • #344 Fixed where lifecycle hook defined at model was not bound to the model object.
  • #504 Fixed where first and last method was returning undefined instead of null when data is empty.
Compare
Choose a tag to compare

New Features

New UID attribute.

Now you can use the new this.uid attribute for the model fields. This attribute will generate a unique ID if the field is not present when inserting a record.

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      id: this.uid(),
      name: this.string('')
    }
  }
}

This attribute will generate a unique string value that looks like this.

const user = new User()

user.id // <- '$uid32'

The default UID generation is a really simple one. It will have an incremented number with $uid prefix. It's going to be unique for single client usage, but it's not a Universally Unique ID (UUID).

If you need stronger ID generation (like UUID or CID), you can pass your desired function that returns the ID.

class User extends Model {
  static entity = 'users'

  static fields () {
    return {
      id: this.uid(() => uuid())
    }
  }
}

Increment attribute is now deprecated

The increment attribute is now deprecated and will be removed at v2.0.0. Also, the Increment field will now work as an alias to the new UID attribute. Sorry for the inconcinience, though UID is a much simpler approach, and we thought having increment ID is really not that useful in front-end anyway.

Fixes

  • #458 Fixed where the type of whereHas constraint argument was not assignable to type parameter of type 'Constraint'. Thanks to @Emily-RoseSteyn for the PR!