struct

DynFork::Model

Inherits DynFork::QPaladins < DynFork::QPaladins::Fixtures < DynFork::QPaladins::Save < DynFork::QPaladins::Password < DynFork::QPaladins::Check < DynFork::QPaladins::Groups < DynFork::QPaladins::Caching < DynFork::QPaladins::Tools < DynFork::Globals::Date < JSON::Serializable < DynFork::Extra < Struct < Value < Object

Abstraction for converting Crystal structures into DynFork Models.

Simple example:

@[DynFork::Meta(service_name: "Accounts")]
struct User < DynFork::Model
  getter username = DynFork::Fields::TextField.new
  getter birthday = DynFork::Fields::DateField.new
end

Extended example:

@[DynFork::Meta(
  service_name: "Accounts",
  delete_doc?: false,
)]
struct User < DynFork::Model
  getter username = DynFork::Fields::TextField.new(
    label: "Username",
    maxlength: 150,
    minlength: 1,
    regex: "^[a-zA-Z0-9_@.+]$",
    regex_err_msg: "Allowed chars: a-z A-Z 0-9 _ @ . +",
    required: true,
    unique: true
  )
  getter email = DynFork::Fields::EmailField.new(
    label: "E-mail",
    maxlength: 320,
    required: true,
    unique: true
  )
  getter birthday = DynFork::Fields::DateField.new(
    label: "Birthday",
  )
  getter slug = DynFork::Fields::SlugField.new(
    label: "Slug",
    slug_sources: ["hash", "username"]
  )
  getter password = DynFork::Fields::PasswordField.new(
    label: "Password",
  )
  # Do not save the value of this field to the database.
  # This field is for verification purposes only.
  getter confirm_password = DynFork::Fields::PasswordField.new(
    label: "Confirm password",
    ignored: true
  )
  getter active = DynFork::Fields::BoolField.new(
    label: "is active?",
    default: true
  )
end

Constructors

new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Class methods

full_model_name

Get full Model name = ModuleName::StructureName. NOTE: Examples: Accounts::User | Accounts::UserProfile | Cars::ElectricCar | etc ...

Source
meta

Metadata cache.

Source
meta?

Metadata cache.

Source
subclasses

Get a list of Models.

Source

Instance methods

created_at

Field for the date and time the document was created. NOTE: Example: 1970-01-01T00:00:00

Source
hash

Field for the document identifier. NOTE: Example: 507c7f79bcf86cd7994f6c0e

Source
object_id

Get ObjectId from hash field.

Source
updated_at

Field for the date and time the document was updated. NOTE: Example: 1970-01-01T00:00:00

Source