class Guest

Included Modules

Extended Modules

Defined in:

models/guest.cr

Constant Summary

COLUMNS = {"id" => {type: Int64, primary: true, converter: "Int64", db_column_name: "id", crystal_variable_name: id, presence: false, mass_assign: true}, "email" => {type: String, primary: false, converter: "String", db_column_name: "email", crystal_variable_name: email, presence: true, mass_assign: true}, "name" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "name", crystal_variable_name: name, presence: true, mass_assign: true}, "preferred_name" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "preferred_name", crystal_variable_name: preferred_name, presence: true, mass_assign: true}, "phone" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "phone", crystal_variable_name: phone, presence: true, mass_assign: true}, "organisation" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "organisation", crystal_variable_name: organisation, presence: true, mass_assign: true}, "notes" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "notes", crystal_variable_name: notes, presence: true, mass_assign: true}, "photo" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "photo", crystal_variable_name: photo, presence: true, mass_assign: true}, "banned" => {type: Bool, primary: false, converter: "Bool", db_column_name: "banned", crystal_variable_name: banned, presence: true, mass_assign: true}, "dangerous" => {type: Bool, primary: false, converter: "Bool", db_column_name: "dangerous", crystal_variable_name: dangerous, presence: true, mass_assign: true}, "searchable" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "searchable", crystal_variable_name: searchable, presence: true, mass_assign: true}, "extension_data" => {type: JSON::Any, primary: false, converter: "JSON::Any", db_column_name: "extension_data", crystal_variable_name: extension_data, presence: false, mass_assign: true}, "tenant_id" => {type: Int64, primary: false, converter: "Int64", db_column_name: "tenant_id", crystal_variable_name: tenant_id, presence: false, mass_assign: true}} of Nil => Nil
POLYMORPHISM_SETTINGS = {} of Nil => Nil
RELATION_FILTERS = {} of String => (Clear::SQL::SelectBuilder ->)

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.create(x : Hash) : self #

[View source]
def self.create(x : NamedTuple) : self #

[View source]
def self.create(**args) : self #

Build and new model and save it. Returns the model.

The model may not be saved due to validation failure; check the returned model errors? and persisted? flags.


[View source]
def self.create!(a : Hash) : self #

[View source]
def self.create!(x : NamedTuple) : self #

[View source]
def self.create!(**args) : self #

Build and new model and save it. Returns the model.

Returns the newly inserted model Raises an exception if validation failed during the saving process.


[View source]
def self.new(h : Hash(String, _), cache : Clear::Model::QueryCache | Nil = nil, persisted = false, fetch_columns = false) #

[View source]
def self.new(json : JSON::Any, cache : Clear::Model::QueryCache | Nil = nil, persisted = false) #

[View source]
def self.new(t : NamedTuple, persisted = false) #

[View source]
def self.new #

[View source]

Class Method Detail

def self.__call_relation_filter__(name : String, query : Clear::SQL::SelectBuilder) #

[View source]
def self.__relation_filter_attendees__(query) #

def self.build(**x : **T) forall T #

Build a new empty model and fill the columns using the NamedTuple in argument.

Returns the new model


[View source]
def self.by_tenant(tenant_id) #

[View source]
def self.columns #

[View source]
def self.connection : String #

Define on which connection the model is living. Useful in case of models living in different databases.

Is set to "default" by default.

See Clear::SQL#init(URI, *opts) for more information about multi-connections.

Example:

 Clear::SQL.init("postgres://postgres@localhost/database_1", connection_pool_size: 5)
 Clear::SQL.init("secondary", "postgres://postgres@localhost/database_2", connection_pool_size: 5)

class ModelA
  include Clear::Model

  # Performs all the queries on `database_1`
  # self.connection = "default"
  column id : Int32, primary: true, presence: false
  column title : String
end

class ModelB
  include Clear::Model

  # Performs all the queries on `database_2`
  self.connection = "secondary"

  column id : Int32, primary: true, presence: false
end

def self.connection=(connection : String) #

Define on which connection the model is living. Useful in case of models living in different databases.

Is set to "default" by default.

See Clear::SQL#init(URI, *opts) for more information about multi-connections.

Example:

 Clear::SQL.init("postgres://postgres@localhost/database_1", connection_pool_size: 5)
 Clear::SQL.init("secondary", "postgres://postgres@localhost/database_2", connection_pool_size: 5)

class ModelA
  include Clear::Model

  # Performs all the queries on `database_1`
  # self.connection = "default"
  column id : Int32, primary: true, presence: false
  column title : String
end

class ModelB
  include Clear::Model

  # Performs all the queries on `database_2`
  self.connection = "secondary"

  column id : Int32, primary: true, presence: false
end

def self.create(x : Array(NamedTuple)) : Array(self) #

Multi-models creation. See Collection#create(**args)

Returns the list of newly created model.

Each model will call an INSERT query. You may want to use Collection#import to insert multiple model more efficiently in one query.


[View source]
def self.create!(x : Array(NamedTuple)) : Array(self) #

Multi-models creation. See Collection#create!(**args)

Returns the list of newly created model. Raises exception if any of the model has validation error.


[View source]
def self.create_from_json(string_or_io : String | IO, trusted : Bool = false) #

Create a new model from json and save it. Returns the model.

The model may not be saved due to validation failure; check the returned model errors? and persisted? flags. Trusted flag set to true will allow mass assignment without protection, FALSE by default


def self.create_from_json!(string_or_io : String | IO, trusted : Bool = false) #

Create a new model from json and save it. Returns the model.

Returns the newly inserted model Raises an exception if validation failed during the saving process. Trusted flag set to true will allow mass assignment without protection, FALSE by default


def self.find(x) #

Returns a model using primary key equality Returns nil if not found.


[View source]
def self.find!(x) #

Returns a model using primary key equality. Raises error if the model is not found.


[View source]
def self.from_json(string_or_io : String | IO, trusted : Bool = false) #

Create a new empty model and fill the columns from json. Returns the new model

Trusted flag set to true will allow mass assignment without protection, FALSE by default


def self.full_table_name #

returns the fully qualified and escaped name for this table. add schema if schema is different from 'public' (default schema)

ex: "schema"."table"


[View source]
def self.import(array : Enumerable(self), on_conflict : Clear::SQL::InsertQuery -> | Nil = nil) #

Import a bulk of models in one SQL insert query. Each model must be non-persisted.

on_conflict callback can be optionnaly turned on to manage constraints of the database.

Note: Old models are not modified. This method return a copy of the models as saved in the database.

Example:


 users = [ User.new(id: 1), User.new(id: 2), User.new(id: 3)]
 users = User.import(users)

[View source]
def self.polymorphic? : Bool #

def self.query #

Return a new empty query SELECT * FROM [my_model_table]. Can be refined after that.


[View source]
def self.read_only=(read_only : Bool) #

def self.read_only? : Bool #

def self.schema : Clear::SQL::Symbolic | Nil #

Define the current schema used in PostgreSQL. The value is nil by default, which lead to non-specified schema during the querying, and usage of "public" by PostgreSQL.

This property can be redefined on initialization. Example:

  class MyModel
    include Clear::Model

    self.schema = "my_schema"
  end
  MyModel.query.to_sql # SELECT * FROM "my_schema"."my_models"

def self.schema=(schema : Clear::SQL::Symbolic | Nil) #

Define the current schema used in PostgreSQL. The value is nil by default, which lead to non-specified schema during the querying, and usage of "public" by PostgreSQL.

This property can be redefined on initialization. Example:

  class MyModel
    include Clear::Model

    self.schema = "my_schema"
  end
  MyModel.query.to_sql # SELECT * FROM "my_schema"."my_models"

def self.table : Clear::SQL::Symbolic #

Return the table name setup for this model. By convention, the class name is by default equals to the pluralized underscored string form of the model name. Example:

  MyModel => "my_models"
  Person => "people"
  Project::Info => "project_infos"

The property can be updated at initialization to a custom table name:

  class MyModel
    include Clear::Model

    self.table = "another_table_name"
  end
  MyModel.query.to_sql # SELECT * FROM "another_table_name"

def self.table=(table : Clear::SQL::Symbolic) #

Return the table name setup for this model. By convention, the class name is by default equals to the pluralized underscored string form of the model name. Example:

  MyModel => "my_models"
  Person => "people"
  Project::Info => "project_infos"

The property can be updated at initialization to a custom table name:

  class MyModel
    include Clear::Model

    self.table = "another_table_name"
  end
  MyModel.query.to_sql # SELECT * FROM "another_table_name"

Instance Method Detail

def _cached_attendees : Array(Attendee) | Nil #

def _cached_tenant : Tenant | Nil #

def attendee_for(event_id) #

[View source]
def attendees : Attendee::Collection #

The method attendees is a has_many relation to Attendee


def attending_today(tenant_id, timezone) #

[View source]
def attributes : Hash(String, Clear::SQL::Any) #

Attributes, used when fetch_columns is true


def banned : Bool #

Returns the value of #banned column or throw an exception if the column is not defined.


def banned=(x : Bool) #

Setter for #banned column.


def banned_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter) #

Returns the column object used to manage #banned field

See Clear::Model::Column


def base_to_h #

[View source]
def bookings(future_only = true, limit = 10) #

[View source]
def cache : Clear::Model::QueryCache | Nil #

def changed? #

Return true if the model is dirty (e.g. one or more fields have been changed.). Return false otherwise.


def clear_change_flags #

Reset the #changed? flag on all columns

The model behave like its not dirty anymore and call to save would apply no changes.

Returns self


def dangerous : Bool #

Returns the value of #dangerous column or throw an exception if the column is not defined.


def dangerous=(x : Bool) #

Setter for #dangerous column.


def dangerous_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter) #

Returns the column object used to manage #dangerous field

See Clear::Model::Column


def email : String #

Returns the value of #email column or throw an exception if the column is not defined.


def email=(x : String) #

Setter for #email column.


def email_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #email field

See Clear::Model::Column


def events(future_only = true, limit = 10) #

[View source]
def extension_data : JSON::Any #

Returns the value of #extension_data column or throw an exception if the column is not defined.


def extension_data=(x : JSON::Any) #

Setter for #extension_data column.


def extension_data_column : Clear::Model::Column(JSON::Any, Clear::Model::Converter::JSON::AnyConverter) #

Returns the column object used to manage #extension_data field

See Clear::Model::Column


def for_booking_to_h(visitor : Attendee, booking_details) #

[View source]
def id : Int64 #

Returns the value of #id column or throw an exception if the column is not defined.


def id=(x : Int64) #

Setter for #id column.


def id_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter) #

Returns the column object used to manage #id field

See Clear::Model::Column


def invalidate_caches #

Invalidate local-to-relation cache and eager-loading cache. Useful to forcefully query again when calling relation defined method


def name : String | Nil #

Returns the value of #name column or throw an exception if the column is not defined.


def name=(x : String | Nil) #

Setter for #name column.


def name_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #name field

See Clear::Model::Column


def notes : String | Nil #

Returns the value of #notes column or throw an exception if the column is not defined.


def notes=(x : String | Nil) #

Setter for #notes column.


def notes_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #notes field

See Clear::Model::Column


def organisation : String | Nil #

Returns the value of #organisation column or throw an exception if the column is not defined.


def organisation=(x : String | Nil) #

Setter for #organisation column.


def organisation_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #organisation field

See Clear::Model::Column


def phone : String | Nil #

Returns the value of #phone column or throw an exception if the column is not defined.


def phone=(x : String | Nil) #

Setter for #phone column.


def phone_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #phone field

See Clear::Model::Column


def photo : String | Nil #

Returns the value of #photo column or throw an exception if the column is not defined.


def photo=(x : String | Nil) #

Setter for #photo column.


def photo_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #photo field

See Clear::Model::Column


def preferred_name : String | Nil #

Returns the value of #preferred_name column or throw an exception if the column is not defined.


def preferred_name=(x : String | Nil) #

Setter for #preferred_name column.


def preferred_name_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #preferred_name field

See Clear::Model::Column


def reset(h : Hash(Symbol, _)) #

Set the columns from hash


def reset(h : Hash(String, _)) #

Set the model fields from hash


def reset(t : NamedTuple) #

def reset(from_json : JSON::Any) #

def reset(**t : **T) forall T #

reset flavors


def searchable : String | Nil #

Returns the value of #searchable column or throw an exception if the column is not defined.


def searchable=(x : String | Nil) #

Setter for #searchable column.


def searchable_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter) #

Returns the column object used to manage #searchable field

See Clear::Model::Column


def set(h : Hash(Symbol, _)) #

Set the columns from hash


def set(h : Hash(String, _)) #

Set the model fields from hash


def set(t : NamedTuple) #

def set(from_json : JSON::Any) #

def set(**t : **T) forall T #
Description copied from module Clear::Model::HasColumns

Set one or multiple columns to a specific value This two are equivalents:

model.set(a: 1)
model.a = 1

def set_from_json(string_or_io : String | IO, trusted : Bool = false) #

Set the fields from json passed as argument Trusted flag set to true will allow mass assignment without protection, FALSE by default


def tenant : Tenant #

The method tenant is a belongs_to relation to Tenant


def tenant=(model : Tenant) #

def tenant_id : Int64 #

Returns the value of #tenant_id column or throw an exception if the column is not defined.


def tenant_id=(x : Int64) #

Setter for #tenant_id column.


def tenant_id_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter) #

Returns the column object used to manage #tenant_id field

See Clear::Model::Column


def to_h(visitor : Attendee | Nil, is_parent_metadata, meeting_details) #

[View source]
def to_h(full = false) : Hash(String, Clear::SQL::Any) #

Return a hash version of the columns of this model.


def to_json(emit_nulls : Bool = false) #

def to_json(json : JSON::Builder, emit_nulls = false) #

def update_from_json(string_or_io : String | IO, trusted : Bool = false) #

Set the fields from json passed as argument and call save on the object Trusted flag set to true will allow mass assignment without protection, FALSE by default


def update_from_json!(string_or_io : String | IO, trusted : Bool = false) #

Set the fields from json passed as argument and call save! on the object Trusted flag set to true will allow mass assignment without protection, FALSE by default


def update_h : Hash(String, Clear::SQL::Any) #

Generate the hash for update request (like during save)


def validate #
Description copied from module Clear::Model::HasValidation

This method is called whenever valid? or save is called. By default, #validate is empty and must be overriden by your own validation code.


[View source]
def validate_fields_presence #

For each column, ensure than when needed the column has present information into it.

This method is called on validation.