Releases: vuex-orm/vuex-orm
v0.31.0
New Features
"findIn", whereId
, and whereIdIn
method
PR: #256
Now you can look up records by brand new 3 methods.
Get Mulitple Data by Primary Keys
The findIn
method is going to fetch array of data from the store. The argument is array of ids – primary key value – for the records. Also see whereIdIn
to get class instances instead of plain objects.
// Retrieve array of records by their primary key.
const users = User.findIn([1,2])
/*
[
User { id: 1, name: 'John' },
User: { id: 2, name: 'Jane' }
]
*/
Get A Single Data By Id (using key lookup)
Use whereId
method to fetch a single data by using its id. Filters data faster than other where
methods using key lookup. The argument is the id – primary key value – for the record.
const user = User.query().whereId(1).get();
// User { id: 1, name: 'John' }
Get Multiple Data By Id (using key lookup)
Use whereIdIn
method to fetch multiple data by using their ids. Filters data faster than other where
methods using key lookup. The argument is array of ids – primary key values – for the records.
const user = User.query().whereIdIn([1,2]).get();
// [User { id: 1, age: 20 }, User { id: 2, age: 20 }]
Thanks to @ozum for this wonderful PR 🎉
v0.30.0
New Features
"Save" method to the Model
Issue: #150
Now you can use $save
method at Model.
const user = new User()
user.name = 'John Doe'
user.$save()
See more detail at the documentation.
Thanks to @kkyouhei for the awesome PR!
Nullable type attribute
Issue: #171
You may now chain specific type attributes – string
, number
and boolean
– with nullable
chain to make them accept null
as a value.
class User extends Model {
static fields () {
return {
id: this.number(0).nullable(),
name: this.string('John Doe').nullable(),
active: this.boolean(true).nullable()
}
}
}
Fixes
- Fixed issue where retrieving belongs to many relationship fails when pivot model has
id
property defined at its model.
v0.29.0
Breaking Changes
Define lifecycle hook at Model
Issue: #136
Now you can define lifecycle hooks at Model.
class User extends Model {
static entity = 'users'
static fields () {
...
}
beforeCreate (model) {
// Do domething.
}
afterDelete (model) {
// Do domething.
}
}
With this change, you can no longer define lifecycle hooks at module actions. This is due to internal architecture change. Sorry for the inconvenience but please move all of your lifecycle hook definitions to the corresponding Model.
You can find more detail at here.
New Features
Define and interact state from Model
Now you can define and interact state from Model. You can do things like below.
class User extends Model {
static entity = 'users'
static state = {
fetching: false
}
static fields () {
return { ... }
}
}
User.commit((state) => {
state.fetching = true
})
Please refer to the documentation for more details.
v0.28.0
New Features
Add new
method
Issue: #143
Now you can use new
method to create a fresh record. All fields are filled with default values defined at the model schema.
store.dispatch('entities/users/new')
// Or...
User.new()
// State after `new`
{
entities: {
users: {
data: {
'1': { id: 1, name: 'Default Name' }
}
}
}
}
Add hydrate
method to Model
Issue: #240
Model hydrate
method will take a plain record and fill any missing field defined at The Model schema and then returns a new plain record. It will also hydrate relational records as well.
Please see the documentation for more detail.
Omit registry of modules to Database
Now you may omit to register modules to the Database and pass Model only.
database.register(User)
Fixes
-
#239, #242 Fix where pre-hydrated state not getting instantiated.
From Vuex ORM 0.27.0, Vuex ORM will instantiate records before persisting them to Vuex Store and returns a reference to Vuex Store when fetching them. This behavior caused a problem where if the State is pre-hydrated at server-side – for instance via SSR – then the records get serialized hence the records at client side became plain objects instead of Model instances.Now Vuex ORM will check to see if the records in State is an instance of Model, then if not, instantiate them before returning.
v0.27.0
With this release, there is a breaking change to the lifecycle hook API.
New Features
Save model instances directly to the store
Before, Vuex ORM was instantiating models from records when fetching them via getters. Now the instantiation happens before saving any data to the record, which means, by the time you access the record that has been saved to the state, it's already a model instance.
This will not change any public API, but now you'll be able to use model methods or access model properties in query filters such as orderBy
.