Class: Sequel::Model

Inherits:
Object show all
Extended by:
Enumerable, Inflections, Metaprogramming, ClassMethods
Defined in:
lib/sequel/model.rb,
lib/sequel/model/base.rb,
lib/sequel/model/errors.rb,
lib/sequel/model/associations.rb,
lib/sequel/model/dataset_module.rb

Overview

Sequel::Model is an object relational mapper built on top of Sequel core. Each model class is backed by a dataset instance, and many dataset methods can be called directly on the class. Model datasets return rows as model instances, which have fairly standard ORM instance behavior.

Sequel::Model is built completely out of plugins. Plugins can override any class, instance, or dataset method defined by a previous plugin and call super to get the default behavior. By default, Sequel::Model loads two plugins, Sequel::Model (which is itself a plugin) for the base support, and Sequel::Model::Associations for the associations support.

You can set the SEQUEL_NO_ASSOCIATIONS constant or environment variable to make Sequel not load the associations plugin by default.

Defined Under Namespace

Modules: Associations, ClassMethods, DatasetMethods, InstanceMethods Classes: DatasetModule, DeprecatedColumnsUpdated, Errors

Constant Summary collapse

OPTS =
Sequel::OPTS
DATASET_METHODS =
(Dataset::ACTION_METHODS + Dataset::QUERY_METHODS + [:each_server, :where_all, :where_each, :where_single_value]) - [:and, :or, :[], :columns, :columns!, :delete, :update, :add_graph_aliases]
BOOLEAN_SETTINGS =
[:typecast_empty_string_to_nil, :typecast_on_assignment, :strict_param_setting, :raise_on_save_failure, :raise_on_typecast_failure, :require_modification, :use_transactions, :use_after_commit_rollback]
BEFORE_HOOKS =
[:before_create, :before_update, :before_save, :before_destroy, :before_validation]
AFTER_HOOKS =
[:after_create, :after_update, :after_save, :after_destroy, :after_validation, :after_commit, :after_rollback, :after_destroy_commit, :after_destroy_rollback]
AROUND_HOOKS =
[:around_create, :around_update, :around_save, :around_destroy, :around_validation]
NORMAL_METHOD_NAME_REGEXP =
/\A[A-Za-z_][A-Za-z0-9_]*\z/
SETTER_METHOD_REGEXP =
/=\z/
ANONYMOUS_MODEL_CLASSES =
@Model_cache = {}
ANONYMOUS_MODEL_CLASSES_MUTEX =
Mutex.new
INHERITED_INSTANCE_VARIABLES =
{ :@allowed_columns=>:dup, :@dataset_method_modules=>:dup, :@primary_key=>nil, :@use_transactions=>nil, :@raise_on_save_failure=>nil, :@require_modification=>nil, :@restrict_primary_key=>nil, :@simple_pk=>nil, :@simple_table=>nil, :@strict_param_setting=>nil, :@typecast_empty_string_to_nil=>nil, :@typecast_on_assignment=>nil, :@raise_on_typecast_failure=>nil, :@plugins=>:dup, :@setter_methods=>nil, :@use_after_commit_rollback=>nil, :@fast_pk_lookup_sql=>nil, :@fast_instance_delete_sql=>nil, :@finders=>:dup, :@finder_loaders=>:dup, :@db=>nil, :@default_set_fields_options=>:dup, :@require_valid_table=>nil, :@cache_anonymous_models=>nil, :@dataset_module_class=>nil}
HOOKS =

Empty instance methods to create that the user can override to get hook/callback behavior. Just like any other method defined by Sequel, if you override one of these, you should call super to get the default behavior (while empty by default, they can also be defined by plugins). See the “Model Hooks” guide for more detail on hooks.

[:before_create, :before_update, :before_save, :before_destroy, :before_validation,
  :after_create, :after_update, :after_save, :after_destroy, :after_validation,
  :after_commit, :after_rollback, :after_destroy_commit, :after_destroy_rollback # SEQUEL5: Remove commit/rollback hooks
]
RESTRICTED_SETTER_METHODS =

The setter methods (methods ending with =) that are never allowed to be called automatically via set/update/new/etc..

instance_methods.map(&:to_s).select{|l| l.end_with?('=')}

Constants included from Inflections

Inflections::CAMELIZE_CONVERT_REGEXP, Inflections::CAMELIZE_MODULE_REGEXP, Inflections::DASH, Inflections::DEMODULIZE_CONVERT_REGEXP, Inflections::EMPTY_STRING, Inflections::SLASH, Inflections::UNDERSCORE, Inflections::UNDERSCORE_CONVERT_REGEXP1, Inflections::UNDERSCORE_CONVERT_REGEXP2, Inflections::UNDERSCORE_CONVERT_REPLACE, Inflections::UNDERSCORE_MODULE_REGEXP, Inflections::VALID_CONSTANT_NAME_REGEXP

Constants included from ClassMethods

ClassMethods::FINDER_TYPES

Instance Attribute Summary

Attributes included from ClassMethods

#allowed_columns, #cache_anonymous_models, #dataset_method_modules, #dataset_module_class, #default_set_fields_options, #fast_instance_delete_sql, #fast_pk_lookup_sql, #instance_dataset, #plugins, #primary_key, #raise_on_save_failure, #raise_on_typecast_failure, #require_modification, #require_valid_table, #simple_pk, #simple_table, #strict_param_setting, #typecast_empty_string_to_nil, #typecast_on_assignment, #use_after_commit_rollback, #use_transactions

Method Summary

Methods included from Inflections

clear, irregular, plural, singular, uncountable

Methods included from ClassMethods

<<, Model, [], call, clear_setter_methods_cache, columns, create, dataset, dataset=, dataset_module, db, db=, db_schema, def_Model, def_column_alias, def_dataset_method, dup, find, find_or_create, finder, first_where, freeze, implicit_table_name, include, inherited, initialize_copy, load, method_added, no_primary_key, plugin, prepared_finder, primary_key_hash, qualified_primary_key_hash, restrict_primary_key, restrict_primary_key?, set_allowed_columns, set_dataset, set_primary_key, setter_methods, subset, table_name, unrestrict_primary_key, with_pk, with_pk!

Methods included from Metaprogramming

meta_def