Releases: vuex-orm/vuex-orm
v0.33.0
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
v0.32.4
v0.32.3
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
v0.32.1
v0.32.0
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! 🎉