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
nilif 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
#approvedcolumn or throw an exception if the column is not defined. -
#approved=(x : Bool)
Setter for
#approvedcolumn. -
#approved_at : Int64 | Nil
Returns the value of
#approved_atcolumn or throw an exception if the column is not defined. -
#approved_at=(x : Int64 | Nil)
Setter for
#approved_atcolumn. -
#approved_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#approved_atfield -
#approved_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#approvedfield -
#approver_email : String | Nil
Returns the value of
#approver_emailcolumn or throw an exception if the column is not defined. -
#approver_email=(x : String | Nil)
Setter for
#approver_emailcolumn. -
#approver_email_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#approver_emailfield -
#approver_id : String | Nil
Returns the value of
#approver_idcolumn or throw an exception if the column is not defined. -
#approver_id=(x : String | Nil)
Setter for
#approver_idcolumn. -
#approver_id_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#approver_idfield -
#approver_name : String | Nil
Returns the value of
#approver_namecolumn or throw an exception if the column is not defined. -
#approver_name=(x : String | Nil)
Setter for
#approver_namecolumn. -
#approver_name_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#approver_namefield - #as_h : BookingResponse
-
#asset_id : String
Returns the value of
#asset_idcolumn or throw an exception if the column is not defined. -
#asset_id=(x : String)
Setter for
#asset_idcolumn. -
#asset_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#asset_idfield -
#attributes : Hash(String, Clear::SQL::Any)
Attributes, used when fetch_columns is true
-
#booked_by_email : String
Returns the value of
#booked_by_emailcolumn or throw an exception if the column is not defined. -
#booked_by_email=(x : String)
Setter for
#booked_by_emailcolumn. -
#booked_by_email_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_emailfield -
#booked_by_email_digest : String | Nil
Returns the value of
#booked_by_email_digestcolumn or throw an exception if the column is not defined. -
#booked_by_email_digest=(x : String | Nil)
Setter for
#booked_by_email_digestcolumn. -
#booked_by_email_digest_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_email_digestfield -
#booked_by_id : String
Returns the value of
#booked_by_idcolumn or throw an exception if the column is not defined. -
#booked_by_id=(x : String)
Setter for
#booked_by_idcolumn. -
#booked_by_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_idfield -
#booked_by_name : String
Returns the value of
#booked_by_namecolumn or throw an exception if the column is not defined. -
#booked_by_name=(x : String)
Setter for
#booked_by_namecolumn. -
#booked_by_name_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_by_namefield -
#booked_from : String | Nil
Returns the value of
#booked_fromcolumn or throw an exception if the column is not defined. -
#booked_from=(x : String | Nil)
Setter for
#booked_fromcolumn. -
#booked_from_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booked_fromfield -
#booking_end : Int64
Returns the value of
#booking_endcolumn or throw an exception if the column is not defined. -
#booking_end=(x : Int64)
Setter for
#booking_endcolumn. -
#booking_end_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#booking_endfield -
#booking_start : Int64
Returns the value of
#booking_startcolumn or throw an exception if the column is not defined. -
#booking_start=(x : Int64)
Setter for
#booking_startcolumn. -
#booking_start_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#booking_startfield -
#booking_type : String
Returns the value of
#booking_typecolumn or throw an exception if the column is not defined. -
#booking_type=(x : String)
Setter for
#booking_typecolumn. -
#booking_type_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#booking_typefield - #cache : Clear::Model::QueryCache | Nil
-
#changed?
Return
trueif the model is dirty (e.g. -
#checked_in : Bool
Returns the value of
#checked_incolumn or throw an exception if the column is not defined. -
#checked_in=(x : Bool)
Setter for
#checked_incolumn. -
#checked_in_at : Int64 | Nil
Returns the value of
#checked_in_atcolumn or throw an exception if the column is not defined. -
#checked_in_at=(x : Int64 | Nil)
Setter for
#checked_in_atcolumn. -
#checked_in_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#checked_in_atfield -
#checked_in_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#checked_infield -
#checked_out_at : Int64 | Nil
Returns the value of
#checked_out_atcolumn or throw an exception if the column is not defined. -
#checked_out_at=(x : Int64 | Nil)
Setter for
#checked_out_atcolumn. -
#checked_out_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#checked_out_atfield -
#clear_change_flags
Reset the
#changed?flag on all columns -
#created : Int64 | Nil
Returns the value of
#createdcolumn or throw an exception if the column is not defined. -
#created=(x : Int64 | Nil)
Setter for
#createdcolumn. -
#created_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#createdfield - #current_history : Array(History)
- #current_state : State
-
#deleted : Bool
Returns the value of
#deletedcolumn or throw an exception if the column is not defined. -
#deleted=(x : Bool)
Setter for
#deletedcolumn. -
#deleted_at : Int64 | Nil
Returns the value of
#deleted_atcolumn or throw an exception if the column is not defined. -
#deleted_at=(x : Int64 | Nil)
Setter for
#deleted_atcolumn. -
#deleted_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#deleted_atfield -
#deleted_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#deletedfield -
#department : String | Nil
Returns the value of
#departmentcolumn or throw an exception if the column is not defined. -
#department=(x : String | Nil)
Setter for
#departmentcolumn. -
#department_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#departmentfield -
#description : String | Nil
Returns the value of
#descriptioncolumn or throw an exception if the column is not defined. -
#description=(x : String | Nil)
Setter for
#descriptioncolumn. -
#description_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#descriptionfield -
#email_digest : String | Nil
Returns the value of
#email_digestcolumn or throw an exception if the column is not defined. -
#email_digest=(x : String | Nil)
Setter for
#email_digestcolumn. -
#email_digest_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#email_digestfield -
#event_id : String | Nil
Returns the value of
#event_idcolumn or throw an exception if the column is not defined. -
#event_id=(x : String | Nil)
Setter for
#event_idcolumn. -
#event_id_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#event_idfield -
#extension_data : JSON::Any
Returns the value of
#extension_datacolumn or throw an exception if the column is not defined. -
#extension_data=(x : JSON::Any)
Setter for
#extension_datacolumn. -
#extension_data_column : Clear::Model::Column(JSON::Any, Clear::Model::Converter::JSON::AnyConverter)
Returns the column object used to manage
#extension_datafield -
#history : Array(History)
Returns the value of
#historycolumn or throw an exception if the column is not defined. -
#history=(x : Array(History))
Setter for
#historycolumn. -
#history_column : Clear::Model::Column(Array(History), Booking::History::Converter)
Returns the column object used to manage
#historyfield -
#id : Int64
Returns the value of
#idcolumn or throw an exception if the column is not defined. -
#id=(x : Int64)
Setter for
#idcolumn. -
#id_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#idfield -
#invalidate_caches : self
Invalidate local-to-relation cache and eager-loading cache.
-
#last_changed : Int64 | Nil
Returns the value of
#last_changedcolumn or throw an exception if the column is not defined. -
#last_changed=(x : Int64 | Nil)
Setter for
#last_changedcolumn. -
#last_changed_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#last_changedfield -
#process_state : String | Nil
Returns the value of
#process_statecolumn or throw an exception if the column is not defined. -
#process_state=(x : String | Nil)
Setter for
#process_statecolumn. -
#process_state_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#process_statefield -
#rejected : Bool
Returns the value of
#rejectedcolumn or throw an exception if the column is not defined. -
#rejected=(x : Bool)
Setter for
#rejectedcolumn. -
#rejected_at : Int64 | Nil
Returns the value of
#rejected_atcolumn or throw an exception if the column is not defined. -
#rejected_at=(x : Int64 | Nil)
Setter for
#rejected_atcolumn. -
#rejected_at_column : Clear::Model::Column(Int64 | Nil, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#rejected_atfield -
#rejected_column : Clear::Model::Column(Bool, Clear::Model::Converter::BoolConverter)
Returns the column object used to manage
#rejectedfield -
#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
#timezonecolumn or throw an exception if the column is not defined. -
#timezone=(x : String | Nil)
Setter for
#timezonecolumn. -
#timezone_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#timezonefield -
#title : String | Nil
Returns the value of
#titlecolumn or throw an exception if the column is not defined. -
#title=(x : String | Nil)
Setter for
#titlecolumn. -
#title_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#titlefield -
#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
saveon 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_emailcolumn or throw an exception if the column is not defined. -
#user_email=(x : String)
Setter for
#user_emailcolumn. -
#user_email_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#user_emailfield -
#user_id : String
Returns the value of
#user_idcolumn or throw an exception if the column is not defined. -
#user_id=(x : String)
Setter for
#user_idcolumn. -
#user_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#user_idfield -
#user_name : String
Returns the value of
#user_namecolumn or throw an exception if the column is not defined. -
#user_name=(x : String)
Setter for
#user_namecolumn. -
#user_name_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#user_namefield - #utm_source : String | Nil
- #utm_source=(utm_source : String | Nil)
-
#validate
This method is called whenever
valid?orsaveis 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
#zonescolumn or throw an exception if the column is not defined. -
#zones=(x : Array(String) | Nil)
Setter for
#zonescolumn. -
#zones_column : Clear::Model::Column(Array(String) | Nil, Clear::Model::Converter::ArrayConverterString)
Returns the column object used to manage
#zonesfield
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.