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.