class Onyx::SQL::Model::Changeset(T, U)

Overview

A changeset for a model. Used to track changes made to it. To update a value in a changeset, call #update. This will not affect the original model.

It is instantiated via Model#changeset:

user = User.new(name: "John")
changeset = user.changeset
changeset.update(name: "Jake")
pp changeset.changes # => {"name" => "Jake"}

It is handy to use a changeset with Model#update method. Note that Model#update may raise NoChanges error if the changeset is empty.

Defined in:

onyx-sql/model/changes.cr

Instance Method Summary

Instance Method Detail

def changes : Hash(String, U) #

Return changes on this changeset.


[View source]
def changes! #

Return #changes on this changeset or raise NoChanges if it's empty.


[View source]
def empty? #

Return true if there are no changes on this changeset.


[View source]
def initial_values : Hash(String, U) #

[View source]
def update(**values : **V) : Nil forall V #

Update a changeset value by T instance varialbe. This will not affect the original model.


[View source]
def values : Hash(String, U) #

[View source]