Skip to content

v0.34.0

Compare
Choose a tag to compare
@kiaking kiaking released this 25 Nov 10:56
· 208 commits to master since this release

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!