Skip to content

Releases: vuex-orm/vuex-orm

v0.33.0

30 Oct 09:42
Compare
Choose a tag to compare

Breaking Changes

How Vuex ORM handles the composite primary key has changed. Previously, Vuex ORM stored records with composite primary keys by joining primary key values with an underscore, for example, like 2_1. So it looked like this inside Vuex Store.

{
  subscriptions: {
    '1_1': { ... },
    '1_2': { ... },
    '2_1': { ... }
  }
}

Now, Vuex ORM will store index ID as a stringified array. Like this.

{
  subscriptions: {
    '[1,1]': { ... },
    '[1,2]': { ... },
    '[2,1]': { ... }
  }
}

With this change, now you can query record with composite primary key by passing an array of ids, for example, to find method.

Subscription.find([1, 2])

Please see more details below on what method got updated.

Improvements

Better Composite Primary Key support

Issue #261

Now, you may pass an array of ids to retrieve records with a composite primary key.

Let's say you have a Subscription model defined like this.

import { Model } from '@vuex-orm/core'

class Subscription extends Model {
  static entity = 'users'

  static primaryKey = ['video_id', 'user_id']

  static fields () {
    return {
      video_id: this.attr(null),
      user_id: this.attr(null)
    }
  }
}

Then, you can retrieve Subscription records as below. Remember that the value order in the array is the same as the order you defined in your Model's primary key property. In this case it's ['video_id', 'user_id'].

// Get a subscription with video_id 1 and user_id 2.
const subscription = User.find([1, 2])

// { video_id: 1, user_id: 2 }

You can also delete records in the same way.

// Delete subscription with video_id 1 and user_id 2.
Subscription.delete([1, 2])

Thanks to @lucasbiguet for this wonderful PR!

v0.32.5

21 Oct 00:13
Compare
Choose a tag to compare

Fixes

  • #470 Added missing export Container.
  • #472 Fix type error on Nuxt SSR.

v0.32.4

08 Oct 14:23
Compare
Choose a tag to compare

Fixes

  • #460 Fixed STI models not being instantiated correctly when instantiating a model directly (not through Vuex Getters).

Thanks to @SzNagyMisu for the awesome fix! 🎉

v0.32.3

02 Oct 09:40
Compare
Choose a tag to compare

Fixes

  • #442 Fixed typing error on delete method.
  • #444 Fixed belongsTo and hasOne relationship throwing error when inserting data with the related field of a primitive value.

Thanks to @2-5, @wizardnet972, and @eldomagan for reporting issues and submitting the excellent PR! 👏

v0.32.2

02 Sep 10:31
Compare
Choose a tag to compare

Fixes

  • #391 Fix unexpected error when loading relationships by withAll and withRecursive.
  • #410 Fix hasManyThrough returns [undefined] when trying to load empty relationship.

v0.32.1

23 Jul 13:34
Compare
Choose a tag to compare

Fixes

  • #319 Fixed where toJSON was not compatible with JSON.stringify. The method is now going to return every property of the model instance (not only field that is defined in static fields).

v0.32.0

10 Jul 14:08
Compare
Choose a tag to compare

New Features

Single Table Inheritance (STI) support.

Issue: #310

Vuex ORM now supports Single Table Inheritance (STI) or Sub-classing through ES6 extension (use of the class ... extends ... syntax). STI is a way to emulate object-oriented inheritance in a relational database. If you're coming from Ruby on Rails land, you might be familiar with it.

Basically, it will allow you to get different Model instance based on types of records in the same entity. For example, you might have users entity, and you could have a field called type and it could be Person, Adult, or Child. Now, when you fetch these records, sometime it's useful if we can get each type in its own Model instance. Here is where STI comes in to play nicely.

Please take a look at the documentation for more details.

Huge thanks to @tvillaren for this wonderful PR! 🎉

v0.31.13

08 Jul 12:56
Compare
Choose a tag to compare

Fixes

  • #397 Fix Belongs To Many relationship returning empty model object when the record does not have id.

Thanks @kkyouhei for the awesome fix! 🔥

v0.31.12

23 May 14:55
Compare
Choose a tag to compare

Fixes

  • #304 Fix issue when creating a record with the id value of null sometimes cause an error.
  • #367 Fix where creating morph to many records with incremented id not working correctly.
  • #349 Fix normalizr package not found error on TypeScript.
  • #370 Fix inconsistent typing at with query method.

v0.31.11

14 May 15:14
Compare
Choose a tag to compare

Fixes

  • #303 Fix where combining increment id and relationship which requires "pivot" table not generating correct pivot table when inserting records.

Thanks @nagwan and @phortx for the report! 🔥