Releases: vuex-orm/vuex-orm
v0.11.5
v0.11.4
v0.11.3
v0.11.2
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
v0.11.0
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
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
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
v0.8.0
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' }
]
},
]
}
*/