Releases: vuex-orm/vuex-orm
v0.36.4
v0.36.3
v0.36.2
v0.36.1
v0.36.0
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.
v0.35.2
v0.35.1
v0.35.0
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
v0.34.1
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
v0.34.0
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!