class Booking
- Booking
- Reference
- Object
Overview
Clear version of ORM
Included Modules
- Clear::Model
- Clear::Model::Relations::BelongsToMacro
- Clear::Model::Relations::HasManyMacro
- Clear::Model::Relations::HasManyThroughMacro
- Clear::Model::Relations::HasOneMacro
Extended Modules
- Clear::Model::HasHooks::ClassMethods
Defined in:
pg_benchmark.cr:15pg_benchmark.cr:49
Constant Summary
-
COLUMNS =
{"id" => {type: Int64, primary: true, converter: "Int64", db_column_name: "id", crystal_variable_name: id, presence: false, mass_assign: true}, "user_id" => {type: String, primary: false, converter: "String", db_column_name: "user_id", crystal_variable_name: user_id, presence: true, mass_assign: true}, "user_email" => {type: String, primary: false, converter: "String", db_column_name: "user_email", crystal_variable_name: user_email, presence: true, mass_assign: true}, "user_name" => {type: String, primary: false, converter: "String", db_column_name: "user_name", crystal_variable_name: user_name, presence: true, mass_assign: true}, "asset_id" => {type: String, primary: false, converter: "String", db_column_name: "asset_id", crystal_variable_name: asset_id, presence: true, mass_assign: true}, "zones" => {type: Array(String) | ::Nil, primary: false, converter: "Array(String)", db_column_name: "zones", crystal_variable_name: zones, presence: true, mass_assign: true}, "email_digest" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "email_digest", crystal_variable_name: email_digest, presence: true, mass_assign: true}, "booking_type" => {type: String, primary: false, converter: "String", db_column_name: "booking_type", crystal_variable_name: booking_type, presence: true, mass_assign: true}, "booking_start" => {type: Int64, primary: false, converter: "Int64", db_column_name: "booking_start", crystal_variable_name: booking_start, presence: true, mass_assign: true}, "booking_end" => {type: Int64, primary: false, converter: "Int64", db_column_name: "booking_end", crystal_variable_name: booking_end, presence: true, mass_assign: true}, "timezone" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "timezone", crystal_variable_name: timezone, presence: true, mass_assign: true}, "title" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "title", crystal_variable_name: title, presence: true, mass_assign: true}, "description" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "description", crystal_variable_name: description, presence: true, mass_assign: true}, "deleted" => {type: Bool, primary: false, converter: "Bool", db_column_name: "deleted", crystal_variable_name: deleted, presence: false, mass_assign: true}, "deleted_at" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "deleted_at", crystal_variable_name: deleted_at, presence: true, mass_assign: true}, "checked_in" => {type: Bool, primary: false, converter: "Bool", db_column_name: "checked_in", crystal_variable_name: checked_in, presence: false, mass_assign: true}, "checked_in_at" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "checked_in_at", crystal_variable_name: checked_in_at, presence: true, mass_assign: true}, "checked_out_at" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "checked_out_at", crystal_variable_name: checked_out_at, presence: true, mass_assign: true}, "rejected" => {type: Bool, primary: false, converter: "Bool", db_column_name: "rejected", crystal_variable_name: rejected, presence: false, mass_assign: true}, "rejected_at" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "rejected_at", crystal_variable_name: rejected_at, presence: true, mass_assign: true}, "approved" => {type: Bool, primary: false, converter: "Bool", db_column_name: "approved", crystal_variable_name: approved, presence: false, mass_assign: true}, "approved_at" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "approved_at", crystal_variable_name: approved_at, presence: true, mass_assign: true}, "approver_id" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "approver_id", crystal_variable_name: approver_id, presence: true, mass_assign: true}, "approver_email" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "approver_email", crystal_variable_name: approver_email, presence: true, mass_assign: true}, "approver_name" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "approver_name", crystal_variable_name: approver_name, presence: true, mass_assign: true}, "department" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "department", crystal_variable_name: department, presence: true, mass_assign: true}, "event_id" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "event_id", crystal_variable_name: event_id, presence: true, mass_assign: true}, "booked_by_id" => {type: String, primary: false, converter: "String", db_column_name: "booked_by_id", crystal_variable_name: booked_by_id, presence: true, mass_assign: true}, "booked_by_email" => {type: String, primary: false, converter: "String", db_column_name: "booked_by_email", crystal_variable_name: booked_by_email, presence: true, mass_assign: true}, "booked_by_email_digest" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "booked_by_email_digest", crystal_variable_name: booked_by_email_digest, presence: true, mass_assign: true}, "booked_by_name" => {type: String, primary: false, converter: "String", db_column_name: "booked_by_name", crystal_variable_name: booked_by_name, presence: true, mass_assign: true}, "booked_from" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "booked_from", crystal_variable_name: booked_from, presence: true, mass_assign: true}, "process_state" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "process_state", crystal_variable_name: process_state, presence: true, mass_assign: true}, "last_changed" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "last_changed", crystal_variable_name: last_changed, presence: true, mass_assign: true}, "created" => {type: Int64 | ::Nil, primary: false, converter: "Int64", db_column_name: "created", crystal_variable_name: created, 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}, "history" => {type: Array(History), primary: false, converter: "Array(Booking::History)", db_column_name: "history", crystal_variable_name: history, presence: false, mass_assign: true}} of Nil => Nil
-
POLYMORPHISM_SETTINGS =
{} of Nil => Nil
-
RELATION_FILTERS =
{} of String => (Clear::SQL::SelectBuilder ->)
-
TRUTHY =
{true, "true"}
Constructors
- .create(x : Hash) : self
- .create(x : NamedTuple) : self
-
.create(**args) : self
Build and new model and save it.
- .create!(a : Hash) : self
- .create!(x : NamedTuple) : self
-
.create!(**args) : self
Build and new model and save it.
- .new(h : Hash(String, _), cache : Clear::Model::QueryCache | Nil = nil, persisted = false, fetch_columns = false)
- .new(json : JSON::Any, cache : Clear::Model::QueryCache | Nil = nil, persisted = false)
- .new(t : NamedTuple, persisted = false)
- .new
Class Method Summary
- .__call_relation_filter__(name : String, query : Clear::SQL::SelectBuilder)
- .booked_between(tenant_id, period_start, period_end)
-
.build(**x : **T) forall T
Build a new empty model and fill the columns using the NamedTuple in argument.
- .by_tenant(tenant_id)
- .by_user_id(user_id)
- .by_user_or_email(user_id_value, user_email_value, include_booked_by)
-
.by_zones(zones)
Bookings have the zones in an array.
- .columns
-
.connection : String
Define on which connection the model is living.
-
.connection=(connection : String)
Define on which connection the model is living.
-
.create(x : Array(NamedTuple)) : Array(self)
Multi-models creation.
-
.create!(x : Array(NamedTuple)) : Array(self)
Multi-models creation.
-
.create_from_json(string_or_io : String | IO, trusted : Bool = false)
Create a new model from json and save it.
-
.create_from_json!(string_or_io : String | IO, trusted : Bool = false)
Create a new model from json and save it.
-
.find(x)
Returns a model using primary key equality Returns
nil
if not found. -
.find!(x)
Returns a model using primary key equality.
-
.from_json(string_or_io : String | IO, trusted : Bool = false)
Create a new empty model and fill the columns from json.
-
.full_table_name
returns the fully qualified and escaped name for this table.
-
.import(array : Enumerable(self), on_conflict : Clear::SQL::InsertQuery -> | Nil = nil)
Import a bulk of models in one SQL insert query.
- .is_approved(value)
- .is_checked_in(value)
- .is_created_after(time)
- .is_created_before(time)
- .is_department(value)
- .is_event_id(event_id)
- .is_extension_data(value)
- .is_rejected(value)
- .is_state(state)
- .polymorphic? : Bool
-
.query
Return a new empty query
SELECT * FROM [my_model_table]
. - .read_only=(read_only : Bool)
- .read_only? : Bool
-
.schema : Clear::SQL::Symbolic | Nil
Define the current schema used in PostgreSQL.
-
.schema=(schema : Clear::SQL::Symbolic | Nil)
Define the current schema used in PostgreSQL.
-
.table : Clear::SQL::Symbolic
Return the table name setup for this model.
-
.table=(table : Clear::SQL::Symbolic)
Return the table name setup for this model.
Instance Method Summary
-
#approved : Bool
Returns the value of
#approved
column or throw an exception if the column is not defined. -
#approved=(x : Bool)
Setter for
#approved
column. -
#approved_at : Int64 | Nil
Returns the value of
#approved_at
column or throw an exception if the column is not defined. -
#approved_at=(x : Int64 | Nil)
Setter for
#approved_at
column. -
#approved_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#approved_at
field -
#approved_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#approved
field -
#approver_email : String | Nil
Returns the value of
#approver_email
column or throw an exception if the column is not defined. -
#approver_email=(x : String | Nil)
Setter for
#approver_email
column. -
#approver_email_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#approver_email
field -
#approver_id : String | Nil
Returns the value of
#approver_id
column or throw an exception if the column is not defined. -
#approver_id=(x : String | Nil)
Setter for
#approver_id
column. -
#approver_id_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#approver_id
field -
#approver_name : String | Nil
Returns the value of
#approver_name
column or throw an exception if the column is not defined. -
#approver_name=(x : String | Nil)
Setter for
#approver_name
column. -
#approver_name_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#approver_name
field - #as_h : BookingResponse
-
#asset_id : String
Returns the value of
#asset_id
column or throw an exception if the column is not defined. -
#asset_id=(x : String)
Setter for
#asset_id
column. -
#asset_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#asset_id
field -
#attributes : Hash(String, Clear::SQL::Any)
Attributes, used when fetch_columns is true
-
#booked_by_email : String
Returns the value of
#booked_by_email
column or throw an exception if the column is not defined. -
#booked_by_email=(x : String)
Setter for
#booked_by_email
column. -
#booked_by_email_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_email
field -
#booked_by_email_digest : String | Nil
Returns the value of
#booked_by_email_digest
column or throw an exception if the column is not defined. -
#booked_by_email_digest=(x : String | Nil)
Setter for
#booked_by_email_digest
column. -
#booked_by_email_digest_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_email_digest
field -
#booked_by_id : String
Returns the value of
#booked_by_id
column or throw an exception if the column is not defined. -
#booked_by_id=(x : String)
Setter for
#booked_by_id
column. -
#booked_by_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_id
field -
#booked_by_name : String
Returns the value of
#booked_by_name
column or throw an exception if the column is not defined. -
#booked_by_name=(x : String)
Setter for
#booked_by_name
column. -
#booked_by_name_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_name
field -
#booked_from : String | Nil
Returns the value of
#booked_from
column or throw an exception if the column is not defined. -
#booked_from=(x : String | Nil)
Setter for
#booked_from
column. -
#booked_from_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_from
field -
#booking_end : Int64
Returns the value of
#booking_end
column or throw an exception if the column is not defined. -
#booking_end=(x : Int64)
Setter for
#booking_end
column. -
#booking_end_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#booking_end
field -
#booking_start : Int64
Returns the value of
#booking_start
column or throw an exception if the column is not defined. -
#booking_start=(x : Int64)
Setter for
#booking_start
column. -
#booking_start_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#booking_start
field -
#booking_type : String
Returns the value of
#booking_type
column or throw an exception if the column is not defined. -
#booking_type=(x : String)
Setter for
#booking_type
column. -
#booking_type_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booking_type
field - #cache : Clear::Model::QueryCache | Nil
-
#changed?
Return
true
if the model is dirty (e.g. -
#checked_in : Bool
Returns the value of
#checked_in
column or throw an exception if the column is not defined. -
#checked_in=(x : Bool)
Setter for
#checked_in
column. -
#checked_in_at : Int64 | Nil
Returns the value of
#checked_in_at
column or throw an exception if the column is not defined. -
#checked_in_at=(x : Int64 | Nil)
Setter for
#checked_in_at
column. -
#checked_in_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#checked_in_at
field -
#checked_in_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#checked_in
field -
#checked_out_at : Int64 | Nil
Returns the value of
#checked_out_at
column or throw an exception if the column is not defined. -
#checked_out_at=(x : Int64 | Nil)
Setter for
#checked_out_at
column. -
#checked_out_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#checked_out_at
field -
#clear_change_flags
Reset the
#changed?
flag on all columns -
#created : Int64 | Nil
Returns the value of
#created
column or throw an exception if the column is not defined. -
#created=(x : Int64 | Nil)
Setter for
#created
column. -
#created_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#created
field - #current_history : Array(History)
- #current_state : State
-
#deleted : Bool
Returns the value of
#deleted
column or throw an exception if the column is not defined. -
#deleted=(x : Bool)
Setter for
#deleted
column. -
#deleted_at : Int64 | Nil
Returns the value of
#deleted_at
column or throw an exception if the column is not defined. -
#deleted_at=(x : Int64 | Nil)
Setter for
#deleted_at
column. -
#deleted_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#deleted_at
field -
#deleted_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#deleted
field -
#department : String | Nil
Returns the value of
#department
column or throw an exception if the column is not defined. -
#department=(x : String | Nil)
Setter for
#department
column. -
#department_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#department
field -
#description : String | Nil
Returns the value of
#description
column or throw an exception if the column is not defined. -
#description=(x : String | Nil)
Setter for
#description
column. -
#description_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#description
field -
#email_digest : String | Nil
Returns the value of
#email_digest
column or throw an exception if the column is not defined. -
#email_digest=(x : String | Nil)
Setter for
#email_digest
column. -
#email_digest_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#email_digest
field -
#event_id : String | Nil
Returns the value of
#event_id
column or throw an exception if the column is not defined. -
#event_id=(x : String | Nil)
Setter for
#event_id
column. -
#event_id_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#event_id
field -
#extension_data : JSON::Any
Returns the value of
#extension_data
column or throw an exception if the column is not defined. -
#extension_data=(x : JSON::Any)
Setter for
#extension_data
column. -
#extension_data_column : Clear::Model::Column(JSON::Any, Clear::Model::Converter::JSON::AnyConverter)
Returns the column object used to manage
#extension_data
field -
#history : Array(History)
Returns the value of
#history
column or throw an exception if the column is not defined. -
#history=(x : Array(History))
Setter for
#history
column. -
#history_column : Clear::Model::Column(Array(History), Booking::History::Converter)
Returns the column object used to manage
#history
field -
#id : Int64
Returns the value of
#id
column or throw an exception if the column is not defined. -
#id=(x : Int64)
Setter for
#id
column. -
#id_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#id
field -
#invalidate_caches : self
Invalidate local-to-relation cache and eager-loading cache.
-
#last_changed : Int64 | Nil
Returns the value of
#last_changed
column or throw an exception if the column is not defined. -
#last_changed=(x : Int64 | Nil)
Setter for
#last_changed
column. -
#last_changed_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#last_changed
field -
#process_state : String | Nil
Returns the value of
#process_state
column or throw an exception if the column is not defined. -
#process_state=(x : String | Nil)
Setter for
#process_state
column. -
#process_state_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#process_state
field -
#rejected : Bool
Returns the value of
#rejected
column or throw an exception if the column is not defined. -
#rejected=(x : Bool)
Setter for
#rejected
column. -
#rejected_at : Int64 | Nil
Returns the value of
#rejected_at
column or throw an exception if the column is not defined. -
#rejected_at=(x : Int64 | Nil)
Setter for
#rejected_at
column. -
#rejected_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#rejected_at
field -
#rejected_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#rejected
field -
#reset(h : Hash(Symbol, _))
Set the columns from hash
-
#reset(h : Hash(String, _))
Set the model fields from hash
- #reset(t : NamedTuple)
- #reset(from_json : JSON::Any)
-
#reset(**t : **T) forall T
reset flavors
-
#set(h : Hash(Symbol, _))
Set the columns from hash
-
#set(h : Hash(String, _))
Set the model fields from hash
- #set(t : NamedTuple)
- #set(from_json : JSON::Any)
-
#set(**t : **T) forall T
Set one or multiple columns to a specific value This two are equivalents:
- #set_created
-
#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
-
#timezone : String | Nil
Returns the value of
#timezone
column or throw an exception if the column is not defined. -
#timezone=(x : String | Nil)
Setter for
#timezone
column. -
#timezone_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#timezone
field -
#title : String | Nil
Returns the value of
#title
column or throw an exception if the column is not defined. -
#title=(x : String | Nil)
Setter for
#title
column. -
#title_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#title
field -
#to_h(full = false) : Hash(String, Clear::SQL::Any)
Return a hash version of the columns of this model.
- #to_json(emit_nulls : Bool = false)
- #to_json(json : JSON::Builder, emit_nulls = false)
-
#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 -
#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 -
#update_h : Hash(String, Clear::SQL::Any)
Generate the hash for update request (like during save)
-
#user_email : String
Returns the value of
#user_email
column or throw an exception if the column is not defined. -
#user_email=(x : String)
Setter for
#user_email
column. -
#user_email_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#user_email
field -
#user_id : String
Returns the value of
#user_id
column or throw an exception if the column is not defined. -
#user_id=(x : String)
Setter for
#user_id
column. -
#user_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#user_id
field -
#user_name : String
Returns the value of
#user_name
column or throw an exception if the column is not defined. -
#user_name=(x : String)
Setter for
#user_name
column. -
#user_name_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#user_name
field - #utm_source : String | Nil
- #utm_source=(utm_source : String | Nil)
-
#validate
This method is called whenever
valid?
orsave
is called. -
#validate_fields_presence
For each column, ensure than when needed the column has present information into it.
-
#zones : Array(String) | Nil
Returns the value of
#zones
column or throw an exception if the column is not defined. -
#zones=(x : Array(String) | Nil)
Setter for
#zones
column. -
#zones_column : Clear::Model::Column(Array(String) | Nil, Clear::Model::Converter::ArrayConverterString)
Returns the column object used to manage
#zones
field
Constructor Detail
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.
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.
Class Method Detail
Build a new empty model and fill the columns using the NamedTuple in argument.
Returns the new model
Bookings have the zones in an array.
In case of multiple zones as input, we return all bookings that have any of the input zones in their zones array
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
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
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.
Multi-models creation. See Collection#create!(**args)
Returns the list of newly created model. Raises exception if any of the model has validation error.
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
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
Returns a model using primary key equality. Raises error if the model is not found.
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
returns the fully qualified and escaped name for this table. add schema if schema is different from 'public' (default schema)
ex: "schema"."table"
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)
Return a new empty query SELECT * FROM [my_model_table]
. Can be refined after that.
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"
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"
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"
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
Returns the value of #approved
column or throw an exception if the column is not defined.
Returns the value of #approved_at
column or throw an exception if the column is not defined.
Returns the column object used to manage #approved_at
field
See Clear::Model::Column
Returns the column object used to manage #approved
field
See Clear::Model::Column
Returns the value of #approver_email
column or throw an exception if the column is not defined.
Returns the column object used to manage #approver_email
field
See Clear::Model::Column
Returns the value of #approver_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #approver_id
field
See Clear::Model::Column
Returns the value of #approver_name
column or throw an exception if the column is not defined.
Returns the column object used to manage #approver_name
field
See Clear::Model::Column
Returns the value of #asset_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #asset_id
field
See Clear::Model::Column
Returns the value of #booked_by_email
column or throw an exception if the column is not defined.
Returns the column object used to manage #booked_by_email
field
See Clear::Model::Column
Returns the value of #booked_by_email_digest
column or throw an exception if the column is not defined.
Returns the column object used to manage #booked_by_email_digest
field
See Clear::Model::Column
Returns the value of #booked_by_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #booked_by_id
field
See Clear::Model::Column
Returns the value of #booked_by_name
column or throw an exception if the column is not defined.
Returns the column object used to manage #booked_by_name
field
See Clear::Model::Column
Returns the value of #booked_from
column or throw an exception if the column is not defined.
Returns the column object used to manage #booked_from
field
See Clear::Model::Column
Returns the value of #booking_end
column or throw an exception if the column is not defined.
Returns the column object used to manage #booking_end
field
See Clear::Model::Column
Returns the value of #booking_start
column or throw an exception if the column is not defined.
Returns the column object used to manage #booking_start
field
See Clear::Model::Column
Returns the value of #booking_type
column or throw an exception if the column is not defined.
Returns the column object used to manage #booking_type
field
See Clear::Model::Column
Return true
if the model is dirty (e.g. one or more fields
have been changed.). Return false
otherwise.
Returns the value of #checked_in
column or throw an exception if the column is not defined.
Returns the value of #checked_in_at
column or throw an exception if the column is not defined.
Returns the column object used to manage #checked_in_at
field
See Clear::Model::Column
Returns the column object used to manage #checked_in
field
See Clear::Model::Column
Returns the value of #checked_out_at
column or throw an exception if the column is not defined.
Returns the column object used to manage #checked_out_at
field
See Clear::Model::Column
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
Returns the value of #created
column or throw an exception if the column is not defined.
Returns the column object used to manage #created
field
See Clear::Model::Column
Returns the value of #deleted
column or throw an exception if the column is not defined.
Returns the value of #deleted_at
column or throw an exception if the column is not defined.
Returns the column object used to manage #deleted_at
field
See Clear::Model::Column
Returns the column object used to manage #deleted
field
See Clear::Model::Column
Returns the value of #department
column or throw an exception if the column is not defined.
Returns the column object used to manage #department
field
See Clear::Model::Column
Returns the value of #description
column or throw an exception if the column is not defined.
Returns the column object used to manage #description
field
See Clear::Model::Column
Returns the value of #email_digest
column or throw an exception if the column is not defined.
Returns the column object used to manage #email_digest
field
See Clear::Model::Column
Returns the value of #event_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #event_id
field
See Clear::Model::Column
Returns the value of #extension_data
column or throw an exception if the column is not defined.
Returns the column object used to manage #extension_data
field
See Clear::Model::Column
Returns the value of #id
column or throw an exception if the column is not defined.
Returns the column object used to manage #id
field
See Clear::Model::Column
Invalidate local-to-relation cache and eager-loading cache. Useful to forcefully query again when calling relation defined method
Returns the value of #last_changed
column or throw an exception if the column is not defined.
Returns the column object used to manage #last_changed
field
See Clear::Model::Column
Returns the value of #process_state
column or throw an exception if the column is not defined.
Returns the column object used to manage #process_state
field
See Clear::Model::Column
Returns the value of #rejected
column or throw an exception if the column is not defined.
Returns the value of #rejected_at
column or throw an exception if the column is not defined.
Returns the column object used to manage #rejected_at
field
See Clear::Model::Column
Returns the column object used to manage #rejected
field
See Clear::Model::Column
Set one or multiple columns to a specific value This two are equivalents:
model.set(a: 1)
model.a = 1
Set the fields from json passed as argument Trusted flag set to true will allow mass assignment without protection, FALSE by default
Returns the value of #timezone
column or throw an exception if the column is not defined.
Returns the column object used to manage #timezone
field
See Clear::Model::Column
Returns the value of #title
column or throw an exception if the column is not defined.
Returns the column object used to manage #title
field
See Clear::Model::Column
Return a hash version of the columns of this model.
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
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
Generate the hash for update request (like during save)
Returns the value of #user_email
column or throw an exception if the column is not defined.
Returns the column object used to manage #user_email
field
See Clear::Model::Column
Returns the value of #user_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #user_id
field
See Clear::Model::Column
Returns the value of #user_name
column or throw an exception if the column is not defined.
Returns the column object used to manage #user_name
field
See Clear::Model::Column
This method is called whenever valid?
or save
is called.
By default, #validate
is empty and must be overriden by your own validation code.
For each column, ensure than when needed the column has present information into it.
This method is called on validation.