Class | Sequel::Model
In: | lib/sequel/model.rb lib/sequel/model/associations.rb lib/sequel/model/base.rb lib/sequel/model/errors.rb lib/sequel/model/plugins.rb
Parent: | Object

`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, the only method not part of a plugin is the plugin method itself. Plugins can override any class, instance, or dataset method defined by a previous plugin and call super to get the default behavior.

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

### Methods

plugin

### Included Modules

Metaprogramming

### Classes and Modules

Module Sequel::Model::Associations
Module Sequel::Model::ClassMethods
Module Sequel::Model::DatasetMethods
Module Sequel::Model::InstanceMethods
Class Sequel::Model::Errors

### Constants

ANONYMOUS_MODEL_CLASSES | = | {} |  | Map that stores model classes created with `Sequel::Model()`, to allow the reopening of classes when dealing with code reloading.
DATASET_METHODS | = | (Dataset::ACTION_METHODS + Dataset::QUERY_METHODS + [:eager, :eager_graph, :each_page, :each_server, :print]) - [:and, :or, :[], :[]=, :columns, :columns!] |  | Class methods added to model that call the method of the same name on the dataset
EMPTY_INSTANCE_VARIABLES | = | [:@overridable_methods_module, :@db] |  | Class instance variables to set to nil when a subclass is created, for -w compliance
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] |  | Boolean settings that can be modified at the global, class, or instance level.
BEFORE_HOOKS | = | [:before_create, :before_update, :before_save, :before_destroy, :before_validation] |  | Hooks that are called before an action. Can return false to not do the action. When overriding these, it is recommended to call `super` as the last line of your method, so later hooks are called before earlier hooks.
AFTER_HOOKS | = | [:after_initialize, :after_create, :after_update, :after_save, :after_destroy, :after_validation] |  | Hooks that are called after an action. When overriding these, it is recommended to call `super` on the first line of your method, so later hooks are called after earlier hooks.
HOOKS | = | BEFORE_HOOKS + AFTER_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.

INHERITED_INSTANCE_VARIABLES

=

{:@allowed_columns=>:dup, :@dataset_methods=>:dup, :@dataset_method_modules=>:dup, :@primary_key=>nil, :@use_transactions=>nil, :@raise_on_save_failure=>nil, :@require_modification=>nil, :@restricted_columns=>:dup, :@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}

Class instance variables that are inherited in subclasses. If the value is `:dup`, dup is called on the superclass‘s instance variable when creating the instance variable in the subclass. If the value is `nil`, the superclass‘s instance variable is used directly in the subclass.

NORMAL_METHOD_NAME_REGEXP | = | /\A[A-Za-z_][A-Za-z0-9_]*\z/ |  | Regular expression that determines if a method name is normal in the sense that it could be used literally in ruby code without using send. Used to avoid problems when using eval with a string to define methods.
SETTER_METHOD_REGEXP | = | /=\z/ |  | Regular expression that determines if the method is a valid setter name (i.e. it ends with =).
RESTRICTED_SETTER_METHODS | = | instance_methods.map{|x| x.to_s}.grep(SETTER_METHOD_REGEXP) |  | The setter methods (methods ending with =) that are never allowed to be called automatically via `set`/`update`/`new`/etc..

### Public Class methods

plugin(plugin, *args, &blk)

Loads a plugin for use with the model class, passing optional arguments to the plugin. If the plugin is a module, load it directly. Otherwise, require the plugin from either sequel/plugins/#{plugin} or sequel_#{plugin}, and then attempt to load the module using a the camelized plugin name under Sequel::Plugins.

[Source]

        # File lib/sequel/model/plugins.rb, line 31
    31:     def self.plugin(plugin, *args, &blk)
    32:       m = plugin.is_a?(Module) ? plugin : plugin_module(plugin)
    33:       unless @plugins.include?(m)
    34:         @plugins << m
    35:         m.apply(self, *args, &blk) if m.respond_to?(:apply)
    36:         include(m::InstanceMethods) if m.const_defined?("InstanceMethods")
    37:         extend(m::ClassMethods)if m.const_defined?("ClassMethods")
    38:         if m.const_defined?("DatasetMethods")
    39:           dataset.extend(m::DatasetMethods) if @dataset
    40:           dataset_method_modules << m::DatasetMethods
    41:           meths = m::DatasetMethods.public_instance_methods.reject{|x| NORMAL_METHOD_NAME_REGEXP !~ x.to_s}
    42:           def_dataset_method(*meths) unless meths.empty?
    43:         end
    44:       end
    45:       m.configure(self, *args, &blk) if m.respond_to?(:configure)
    46:     end

[Validate]