class EventMetadata
- EventMetadata
- Reference
- Object
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:
models/event_metadata.crConstant Summary
-
COLUMNS =
{"id" => {type: Int64, primary: true, converter: "Int64", db_column_name: "id", crystal_variable_name: id, presence: false, mass_assign: true}, "system_id" => {type: String, primary: false, converter: "String", db_column_name: "system_id", crystal_variable_name: system_id, presence: true, mass_assign: true}, "event_id" => {type: String, primary: false, converter: "String", db_column_name: "event_id", crystal_variable_name: event_id, presence: true, mass_assign: true}, "recurring_master_id" => {type: String | ::Nil, primary: false, converter: "String", db_column_name: "recurring_master_id", crystal_variable_name: recurring_master_id, presence: true, mass_assign: true}, "ical_uid" => {type: String, primary: false, converter: "String", db_column_name: "ical_uid", crystal_variable_name: ical_uid, presence: true, mass_assign: true}, "host_email" => {type: String, primary: false, converter: "String", db_column_name: "host_email", crystal_variable_name: host_email, presence: true, mass_assign: true}, "resource_calendar" => {type: String, primary: false, converter: "String", db_column_name: "resource_calendar", crystal_variable_name: resource_calendar, presence: true, mass_assign: true}, "event_start" => {type: Int64, primary: false, converter: "Int64", db_column_name: "event_start", crystal_variable_name: event_start, presence: true, mass_assign: true}, "event_end" => {type: Int64, primary: false, converter: "Int64", db_column_name: "event_end", crystal_variable_name: event_end, presence: true, mass_assign: true}, "ext_data" => {type: JSON::Any | ::Nil, primary: false, converter: "JSON::Any", db_column_name: "ext_data", crystal_variable_name: ext_data, presence: true, 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
- .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)
- .__relation_filter_attendees__(query)
-
.build(**x : **T) forall T
Build a new empty model and fill the columns using the NamedTuple in argument.
- .by_tenant(tenant_id)
- .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.
- .migrate_recurring_metadata(system_id : String, recurrance : PlaceCalendar::Event, parent_metadata : EventMetadata)
- .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
- #_cached_attendees : Array(Attendee) | Nil
- #_cached_tenant : Tenant | Nil
-
#attendees : Attendee::Collection
The method attendees is a
has_many
relation to Attendee -
#attributes : Hash(String, Clear::SQL::Any)
Attributes, used when fetch_columns is true
- #cache : Clear::Model::QueryCache | Nil
-
#changed?
Return
true
if the model is dirty (e.g. -
#clear_change_flags
Reset the
#changed?
flag on all columns -
#event_end : Int64
Returns the value of
#event_end
column or throw an exception if the column is not defined. -
#event_end=(x : Int64)
Setter for
#event_end
column. -
#event_end_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#event_end
field -
#event_id : String
Returns the value of
#event_id
column or throw an exception if the column is not defined. -
#event_id=(x : String)
Setter for
#event_id
column. -
#event_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#event_id
field -
#event_start : Int64
Returns the value of
#event_start
column or throw an exception if the column is not defined. -
#event_start=(x : Int64)
Setter for
#event_start
column. -
#event_start_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#event_start
field -
#ext_data : JSON::Any | Nil
Returns the value of
#ext_data
column or throw an exception if the column is not defined. -
#ext_data=(x : JSON::Any | Nil)
Setter for
#ext_data
column. -
#ext_data_column : Clear::Model::Column(JSON::Any | Nil, Clear::Model::Converter::JSON::AnyConverter)
Returns the column object used to manage
#ext_data
field -
#host_email : String
Returns the value of
#host_email
column or throw an exception if the column is not defined. -
#host_email=(x : String)
Setter for
#host_email
column. -
#host_email_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#host_email
field -
#ical_uid : String
Returns the value of
#ical_uid
column or throw an exception if the column is not defined. -
#ical_uid=(x : String)
Setter for
#ical_uid
column. -
#ical_uid_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#ical_uid
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
Invalidate local-to-relation cache and eager-loading cache.
-
#recurring_master_id : String | Nil
Returns the value of
#recurring_master_id
column or throw an exception if the column is not defined. -
#recurring_master_id=(x : String | Nil)
Setter for
#recurring_master_id
column. -
#recurring_master_id_column : Clear::Model::Column(String | Nil, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#recurring_master_id
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
-
#resource_calendar : String
Returns the value of
#resource_calendar
column or throw an exception if the column is not defined. -
#resource_calendar=(x : String)
Setter for
#resource_calendar
column. -
#resource_calendar_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#resource_calendar
field -
#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_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
-
#system_id : String
Returns the value of
#system_id
column or throw an exception if the column is not defined. -
#system_id=(x : String)
Setter for
#system_id
column. -
#system_id_column : Clear::Model::Column(String, Clear::Model::Converter::StringConverter)
Returns the column object used to manage
#system_id
field -
#tenant : Tenant
The method tenant is a
belongs_to
relation to Tenant - #tenant=(model : Tenant)
-
#tenant_id : Int64
Returns the value of
#tenant_id
column or throw an exception if the column is not defined. -
#tenant_id=(x : Int64)
Setter for
#tenant_id
column. -
#tenant_id_column : Clear::Model::Column(Int64, Clear::Model::Converter::Int64Converter)
Returns the column object used to manage
#tenant_id
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)
-
#validate_fields_presence
For each column, ensure than when needed the column has present information into it.
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
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
Return true
if the model is dirty (e.g. one or more fields
have been changed.). Return false
otherwise.
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 #event_end
column or throw an exception if the column is not defined.
Returns the column object used to manage #event_end
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 #event_start
column or throw an exception if the column is not defined.
Returns the column object used to manage #event_start
field
See Clear::Model::Column
Returns the value of #ext_data
column or throw an exception if the column is not defined.
Returns the column object used to manage #ext_data
field
See Clear::Model::Column
Returns the value of #host_email
column or throw an exception if the column is not defined.
Returns the column object used to manage #host_email
field
See Clear::Model::Column
Returns the value of #ical_uid
column or throw an exception if the column is not defined.
Returns the column object used to manage #ical_uid
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 #recurring_master_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #recurring_master_id
field
See Clear::Model::Column
Returns the value of #resource_calendar
column or throw an exception if the column is not defined.
Returns the column object used to manage #resource_calendar
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 #system_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #system_id
field
See Clear::Model::Column
Returns the value of #tenant_id
column or throw an exception if the column is not defined.
Returns the column object used to manage #tenant_id
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)
For each column, ensure than when needed the column has present information into it.
This method is called on validation.