adonis-lucid-update-or-create

1.0.2 • Public • Published

Installation

npm i adonis-lucid-update-or-create --save

Registering provider

Make sure to register the update or create provider inside start/app.js

const providers = [
  "adonis-lucid-update-or-create/providers/UpdateOrCreateProvider"
]

Usage

First add the trait to the model.

const Model = use("Model")
 
class Rating extends Model {
  static boot() {
    super.boot()
 
    this.addTrait("@provider:Lucid/UpdateOrCreate")
  }
}

Finally use the method as follows

const Rating = use("App/Models/Rating")
 
Rating.updateOrCreate(
  {
    user_id: 18,
    article_id: 23
  },
  { rating: 5 }
)

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i adonis-lucid-update-or-create

    Weekly Downloads

    53

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    1.95 kB

    Total Files

    4

    Last publish

    Collaborators

    • michaelz