### Home Classes Methods

### In Files

- lib/sequel/model/base.rb

### Methods

- ::new
- #==
- #===
- #[]
- #[]=
- #_delete
- #_delete_dataset
- #_delete_without_checking
- #_destroy
- #_destroy_delete
- #_insert
- #_insert_dataset
- #_insert_raw
- #_insert_select_raw
- #_refresh
- #_refresh_get
- #_save
- #_save_refresh
- #_save_update_all_columns_hash
- #_update
- #_update_columns
- #_update_dataset
- #_update_without_checking
- #_valid?
- #autoincrementing_primary_key
- #changed_columns
- #checked_save_failure
- #checked_transaction
- #delete
- #destroy
- #each
- #eql?
- #errors
- #exists?
- #extend
- #hash
- #id
- #initialize_set
- #inspect
- #inspect_values
- #keys
- #lock!
- #marshallable!
- #modified!
- #modified?
- #new?
- #pk
- #pk_hash
- #raise_hook_failure
- #raise_on_failure?
- #refresh
- #reload
- #save
- #save_changes
- #set
- #set_all
- #set_except
- #set_fields
- #set_only
- #set_restricted
- #set_server
- #set_values
- #setter_methods
- #singleton_method_added
- #this
- #this_server
- #typecast_value
- #update
- #update_all
- #update_except
- #update_fields
- #update_only
- #update_restricted
- #use_server
- #use_transaction?
- #valid?
- #validate

### Files

- CHANGELOG
- MIT-LICENSE
- README.rdoc
- active_record.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.rdoc
- mass_assignment.rdoc
- migration.rdoc
- model_hooks.rdoc
- opening_databases.rdoc
- prepared_statements.rdoc
- querying.rdoc
- reflection.rdoc
- 1.0.txt
- 1.1.txt
- 1.3.txt
- 1.4.0.txt
- 1.5.0.txt
- 2.0.0.txt
- 2.1.0.txt
- 2.10.0.txt
- 2.11.0.txt
- 2.12.0.txt
- 2.2.0.txt
- 2.3.0.txt
- 2.4.0.txt
- 2.5.0.txt
- 2.6.0.txt
- 2.7.0.txt
- 2.8.0.txt
- 2.9.0.txt
- 3.0.0.txt
- 3.1.0.txt
- 3.10.0.txt
- 3.11.0.txt
- 3.12.0.txt
- 3.13.0.txt
- 3.14.0.txt
- 3.15.0.txt
- 3.16.0.txt
- 3.17.0.txt
- 3.18.0.txt
- 3.19.0.txt
- 3.2.0.txt
- 3.20.0.txt
- 3.21.0.txt
- 3.22.0.txt
- 3.23.0.txt
- 3.24.0.txt
- 3.25.0.txt
- 3.26.0.txt
- 3.27.0.txt
- 3.28.0.txt
- 3.29.0.txt
- 3.3.0.txt
- 3.30.0.txt
- 3.31.0.txt
- 3.32.0.txt
- 3.33.0.txt
- 3.4.0.txt
- 3.5.0.txt
- 3.6.0.txt
- 3.7.0.txt
- 3.8.0.txt
- 3.9.0.txt
- schema_modification.rdoc
- sharding.rdoc
- sql.rdoc
- testing.rdoc
- transactions.rdoc
- validations.rdoc
- virtual_rows.rdoc

### Class Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::ASTTransformer
- Sequel::Access
- Sequel::Access::DatabaseMethods
- Sequel::Access::DatasetMethods
- Sequel::Adapter
- Sequel::AdapterNotFound
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::ArbitraryServers
- Sequel::BasicObject
- Sequel::ColumnsIntrospection
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::DB2Error
- Sequel::DB2::Database
- Sequel::DB2::DatabaseMethods
- Sequel::DB2::Dataset
- Sequel::DB2::DatasetMethods
- Sequel::DBI
- Sequel::DBI::Database
- Sequel::DBI::Dataset
- Sequel::DataObjects
- Sequel::DataObjects::Database
- Sequel::DataObjects::Dataset
- Sequel::DataObjects::MySQL
- Sequel::DataObjects::MySQL::DatabaseMethods
- Sequel::DataObjects::MySQL::Dataset
- Sequel::DataObjects::Postgres
- Sequel::DataObjects::Postgres::AdapterMethods
- Sequel::DataObjects::Postgres::DatabaseMethods
- Sequel::DataObjects::Postgres::Dataset
- Sequel::DataObjects::SQLite
- Sequel::DataObjects::SQLite::DatabaseMethods
- Sequel::DataObjects::SQLite::Dataset
- Sequel::Database
- Sequel::DatabaseConnectionError
- Sequel::DatabaseDisconnectError
- Sequel::DatabaseError
- Sequel::Dataset
- Sequel::Dataset
- Sequel::Dataset::ArgumentMapper
- Sequel::Dataset::BindArgumentMethods
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::TYPE_TRANSLATOR
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::EmulateOffsetWithRowNumber
- Sequel::Error
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::DatabaseMethods
- Sequel::Firebird::Dataset
- Sequel::Firebird::DatasetMethods
- Sequel::HookFailed
- Sequel::HookFailed
- Sequel::IBMDB
- Sequel::IBMDB::Connection
- Sequel::IBMDB::Connection::Error
- Sequel::IBMDB::Database
- Sequel::IBMDB::Dataset
- Sequel::IBMDB::Dataset::CallableStatementMethods
- Sequel::IBMDB::Dataset::PreparedStatementMethods
- Sequel::IBMDB::Statement
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::DatabaseMethods
- Sequel::Informix::Dataset
- Sequel::Informix::DatasetMethods
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::DB2
- Sequel::JDBC::DB2::DatabaseMethods
- Sequel::JDBC::DB2::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Derby
- Sequel::JDBC::Derby::DatabaseMethods
- Sequel::JDBC::Derby::Dataset
- Sequel::JDBC::Firebird
- Sequel::JDBC::Firebird::DatabaseMethods
- Sequel::JDBC::Firebird::Dataset
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::HSQLDB
- Sequel::JDBC::HSQLDB::DatabaseMethods
- Sequel::JDBC::HSQLDB::Dataset
- Sequel::JDBC::Informix
- Sequel::JDBC::Informix::DatabaseMethods
- Sequel::JDBC::Informix::Dataset
- Sequel::JDBC::JTDS
- Sequel::JDBC::JTDS::DatabaseMethods
- Sequel::JDBC::JTDS::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MySQL
- Sequel::JDBC::MySQL::DatabaseMethods
- Sequel::JDBC::MySQL::Dataset
- Sequel::JDBC::Oracle
- Sequel::JDBC::Oracle::DatabaseMethods
- Sequel::JDBC::Oracle::Dataset
- Sequel::JDBC::Postgres
- Sequel::JDBC::Postgres::AdapterMethods
- Sequel::JDBC::Postgres::DatabaseMethods
- Sequel::JDBC::Postgres::Dataset
- Sequel::JDBC::SQLServer
- Sequel::JDBC::SQLServer::DatabaseMethods
- Sequel::JDBC::SQLServer::DatabaseMethods::MetadataDatasetMethods
- Sequel::JDBC::SQLServer::Dataset
- Sequel::JDBC::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::JDBC::Transactions
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationAlterTableReverser
- Sequel::MigrationDSL
- Sequel::MigrationReverser
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Mock
- Sequel::Mock::Connection
- Sequel::Mock::Database
- Sequel::Mock::Dataset
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- Sequel::Model::Associations::EagerGraphLoader
- Sequel::Model::Associations::InstanceMethods
- Sequel::Model::Associations::ManyToManyAssociationReflection
- Sequel::Model::Associations::ManyToOneAssociationReflection
- Sequel::Model::Associations::OneToManyAssociationReflection
- Sequel::Model::Associations::OneToOneAssociationReflection
- Sequel::Model::ClassMethods
- Sequel::Model::DatasetMethods
- Sequel::Model::Errors
- Sequel::Model::InstanceMethods
- Sequel::MySQL
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::DatasetMethods
- Sequel::MySQL::DatasetMethods::CallableStatementMethods
- Sequel::MySQL::DatasetMethods::PreparedStatementMethods
- Sequel::MySQL::DatasetMethods::StoredProcedureMethods
- Sequel::MySQL::PreparedStatements
- Sequel::MySQL::PreparedStatements::DatabaseMethods
- Sequel::Mysql2
- Sequel::Mysql2::Database
- Sequel::Mysql2::Dataset
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NoExistingObject
- Sequel::NotImplemented
- Sequel::ODBC
- Sequel::ODBC::DB2
- Sequel::ODBC::DB2::DatabaseMethods
- Sequel::ODBC::DB2::Dataset
- Sequel::ODBC::Database
- Sequel::ODBC::Dataset
- Sequel::ODBC::MSSQL
- Sequel::ODBC::MSSQL::DatabaseMethods
- Sequel::ODBC::MSSQL::Dataset
- Sequel::OpenBase
- Sequel::OpenBase::Database
- Sequel::OpenBase::Dataset
- Sequel::Oracle
- Sequel::Oracle::Database
- Sequel::Oracle::DatabaseMethods
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::ClassMethods
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationAutoreloading
- Sequel::Plugins::AssociationAutoreloading::ClassMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- Sequel::Plugins::AssociationPks::InstanceMethods
- Sequel::Plugins::AssociationProxies
- Sequel::Plugins::AssociationProxies::AssociationProxy
- Sequel::Plugins::AssociationProxies::ClassMethods
- Sequel::Plugins::BooleanReaders
- Sequel::Plugins::BooleanReaders::ClassMethods
- Sequel::Plugins::Caching
- Sequel::Plugins::Caching::ClassMethods
- Sequel::Plugins::Caching::InstanceMethods
- Sequel::Plugins::ClassTableInheritance
- Sequel::Plugins::ClassTableInheritance::ClassMethods
- Sequel::Plugins::ClassTableInheritance::InstanceMethods
- Sequel::Plugins::Composition
- Sequel::Plugins::Composition::ClassMethods
- Sequel::Plugins::Composition::InstanceMethods
- Sequel::Plugins::DatasetAssociations
- Sequel::Plugins::DatasetAssociations::ClassMethods
- Sequel::Plugins::DatasetAssociations::DatasetMethods
- Sequel::Plugins::DefaultsSetter
- Sequel::Plugins::DefaultsSetter::ClassMethods
- Sequel::Plugins::DefaultsSetter::InstanceMethods
- Sequel::Plugins::ForceEncoding
- Sequel::Plugins::ForceEncoding::ClassMethods
- Sequel::Plugins::ForceEncoding::InstanceMethods
- Sequel::Plugins::HookClassMethods
- Sequel::Plugins::HookClassMethods::ClassMethods
- Sequel::Plugins::HookClassMethods::InstanceMethods
- Sequel::Plugins::IdentityMap
- Sequel::Plugins::IdentityMap::ClassMethods
- Sequel::Plugins::IdentityMap::InstanceMethods
- Sequel::Plugins::InstanceFilters
- Sequel::Plugins::InstanceFilters::InstanceMethods
- Sequel::Plugins::InstanceHooks
- Sequel::Plugins::InstanceHooks::InstanceMethods
- Sequel::Plugins::JsonSerializer
- Sequel::Plugins::JsonSerializer::ClassMethods
- Sequel::Plugins::JsonSerializer::DatasetMethods
- Sequel::Plugins::JsonSerializer::InstanceMethods
- Sequel::Plugins::JsonSerializer::Literal
- Sequel::Plugins::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::List
- Sequel::Plugins::List::ClassMethods
- Sequel::Plugins::List::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- Sequel::Plugins::ManyThroughMany::DatasetMethods
- Sequel::Plugins::ManyThroughMany::ManyThroughManyAssociationReflection
- Sequel::Plugins::NestedAttributes
- Sequel::Plugins::NestedAttributes::ClassMethods
- Sequel::Plugins::NestedAttributes::InstanceMethods
- Sequel::Plugins::OptimisticLocking
- Sequel::Plugins::OptimisticLocking::ClassMethods
- Sequel::Plugins::OptimisticLocking::InstanceMethods
- Sequel::Plugins::PreparedStatements
- Sequel::Plugins::PreparedStatements::ClassMethods
- Sequel::Plugins::PreparedStatements::InstanceMethods
- Sequel::Plugins::PreparedStatementsAssociations
- Sequel::Plugins::PreparedStatementsAssociations::ClassMethods
- Sequel::Plugins::PreparedStatementsAssociations::InstanceMethods
- Sequel::Plugins::PreparedStatementsSafe
- Sequel::Plugins::PreparedStatementsSafe::ClassMethods
- Sequel::Plugins::PreparedStatementsSafe::InstanceMethods
- Sequel::Plugins::PreparedStatementsWithPk
- Sequel::Plugins::PreparedStatementsWithPk::ClassMethods
- Sequel::Plugins::PreparedStatementsWithPk::DatasetMethods
- Sequel::Plugins::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::InstanceMethods
- Sequel::Plugins::SerializationModificationDetection
- Sequel::Plugins::SerializationModificationDetection::InstanceMethods
- Sequel::Plugins::Sharding
- Sequel::Plugins::Sharding::ClassMethods
- Sequel::Plugins::Sharding::DatasetMethods
- Sequel::Plugins::Sharding::InstanceMethods
- Sequel::Plugins::SingleTableInheritance
- Sequel::Plugins::SingleTableInheritance::ClassMethods
- Sequel::Plugins::SingleTableInheritance::InstanceMethods
- Sequel::Plugins::SkipCreateRefresh
- Sequel::Plugins::SkipCreateRefresh::InstanceMethods
- Sequel::Plugins::StringStripper
- Sequel::Plugins::StringStripper::InstanceMethods
- Sequel::Plugins::Subclasses
- Sequel::Plugins::Subclasses::ClassMethods
- Sequel::Plugins::TacticalEagerLoading
- Sequel::Plugins::TacticalEagerLoading::DatasetMethods
- Sequel::Plugins::TacticalEagerLoading::InstanceMethods
- Sequel::Plugins::Timestamps
- Sequel::Plugins::Timestamps::ClassMethods
- Sequel::Plugins::Timestamps::InstanceMethods
- Sequel::Plugins::Touch
- Sequel::Plugins::Touch::ClassMethods
- Sequel::Plugins::Touch::InstanceMethods
- Sequel::Plugins::Tree
- Sequel::Plugins::Tree::ClassMethods
- Sequel::Plugins::Tree::InstanceMethods
- Sequel::Plugins::Tree::SingleRoot
- Sequel::Plugins::Tree::SingleRoot::ClassMethods
- Sequel::Plugins::Tree::SingleRoot::InstanceMethods
- Sequel::Plugins::Tree::TreeMultipleRootError
- Sequel::Plugins::TypecastOnLoad
- Sequel::Plugins::TypecastOnLoad::ClassMethods
- Sequel::Plugins::TypecastOnLoad::InstanceMethods
- Sequel::Plugins::UpdatePrimaryKey
- Sequel::Plugins::UpdatePrimaryKey::ClassMethods
- Sequel::Plugins::UpdatePrimaryKey::InstanceMethods
- Sequel::Plugins::ValidationClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods
- Sequel::Plugins::ValidationClassMethods::ClassMethods::Generator
- Sequel::Plugins::ValidationClassMethods::InstanceMethods
- Sequel::Plugins::ValidationHelpers
- Sequel::Plugins::ValidationHelpers::InstanceMethods
- Sequel::Plugins::XmlSerializer
- Sequel::Plugins::XmlSerializer::ClassMethods
- Sequel::Plugins::XmlSerializer::DatasetMethods
- Sequel::Plugins::XmlSerializer::InstanceMethods
- Sequel::PoolTimeout
- Sequel::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::AdapterMethods
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- Sequel::Qualifier
- Sequel::Rollback
- Sequel::Rollback
- Sequel::SQL
- Sequel::SQL::AliasMethods
- Sequel::SQL::AliasedExpression
- Sequel::SQL::BitwiseMethods
- Sequel::SQL::Blob
- Sequel::SQL::BooleanConstant
- Sequel::SQL::BooleanExpression
- Sequel::SQL::BooleanMethods
- Sequel::SQL::CaseExpression
- Sequel::SQL::Cast
- Sequel::SQL::CastMethods
- Sequel::SQL::ColumnAll
- Sequel::SQL::ComplexExpression
- Sequel::SQL::ComplexExpressionMethods
- Sequel::SQL::Constant
- Sequel::SQL::Constants
- Sequel::SQL::Expression
- Sequel::SQL::Function
- Sequel::SQL::GenericComplexExpression
- Sequel::SQL::GenericExpression
- Sequel::SQL::Identifier
- Sequel::SQL::IdentifierMethods
- Sequel::SQL::InequalityMethods
- Sequel::SQL::JoinClause
- Sequel::SQL::JoinOnClause
- Sequel::SQL::JoinUsingClause
- Sequel::SQL::NegativeBooleanConstant
- Sequel::SQL::NoBooleanInputMethods
- Sequel::SQL::NumericExpression
- Sequel::SQL::NumericMethods
- Sequel::SQL::OrderMethods
- Sequel::SQL::OrderedExpression
- Sequel::SQL::PlaceholderLiteralString
- Sequel::SQL::QualifiedIdentifier
- Sequel::SQL::QualifyingMethods
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::ValueList
- Sequel::SQL::ValueList
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLTime
- Sequel::SQLite
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ServerBlock
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::Swift
- Sequel::Swift::Database
- Sequel::Swift::Dataset
- Sequel::Swift::MySQL
- Sequel::Swift::MySQL::DatabaseMethods
- Sequel::Swift::MySQL::Dataset
- Sequel::Swift::Postgres
- Sequel::Swift::Postgres::AdapterMethods
- Sequel::Swift::Postgres::DatabaseMethods
- Sequel::Swift::Postgres::Dataset
- Sequel::Swift::SQLite
- Sequel::Swift::SQLite::DatabaseMethods
- Sequel::Swift::SQLite::Dataset
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::ThreadedServerBlock
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::TinyTDS
- Sequel::TinyTDS::Database
- Sequel::TinyTDS::Dataset
- Sequel::TinyTDS::Dataset::ArgumentMapper
- Sequel::TinyTDS::Dataset::PreparedStatementMethods
- Sequel::ToDot
- Sequel::UnbindDuplicate
- Sequel::Unbinder
- Sequel::UndefinedAssociation
- Sequel::UnthreadedServerBlock
- Sequel::ValidationFailed
- Dataset
- Dataset::ArgumentMapper
- Dataset::BindArgumentMethods
- Dataset::PreparedStatementMethods
- String
- String::Inflections
- Array
- FalseClass
- Hash
- NilClass
- Numeric
- Object
- PGconn
- PGresult
- Proc
- Symbol
- TrueClass

No matching classes.

# Sequel::Model::InstanceMethods

Sequel::Model instance methods that implement basic model functionality.

- All of the methods in `HOOKS` and `AROUND_HOOKS` create instance methods that are called by Sequel when the appropriate action occurs. For example, when destroying a model object, Sequel will call `around_destroy`, which will call `before_destroy`, do the destroy, and then call `after_destroy`.

- The following instance_methods all call the class method of the same name: columns, db, primary_key, db_schema.

- All of the methods in `BOOLEAN_SETTINGS` create attr_writers allowing you to set values for the attribute. It also creates instance getters returning the value of the setting. If the value has not yet been set, it gets the default value from the class by calling the class method of the same name.

### Attributes

values[R]

The hash of attribute values. Keys are symbols with the names of the underlying database columns.

      Artist.new(:name=>'Bob').values # => {:name=>'Bob'}
      Artist[1].values # => {:id=>1, :name=>'Jim', ...}

### Public Class Methods

new(values = {}, from_db = false) click to toggle source

Creates new instance and passes the given values to set. If a block is given, yield the instance to the block unless from_db is true. This method runs the after_initialize hook after it has optionally yielded itself to the block.

Arguments:

values | should be a hash to pass to set.
from_db | only for backwards compatibility, forget it exists.

      Artist.new(:name=>'Bob')

      Artist.new do |a|
        a.name = 'Bob'
      end

         # File lib/sequel/model/base.rb, line 856
    856:       def initialize(values = {}, from_db = false)
    857:         if from_db
    858:           set_values(values)
    859:         else
    860:           @values = {}
    861:           @new = true
    862:           @modified = true
    863:           initialize_set(values)
    864:           changed_columns.clear
    865:           yield self if block_given?
    866:         end
    867:         after_initialize
    868:       end

### Public Instance Methods

==(obj) click to toggle source

Alias of eql?

         # File lib/sequel/model/base.rb, line 898
    898:       def ==(obj)
    899:         eql?(obj)
    900:       end

===(obj) click to toggle source

If pk is not nil, true only if the objects have the same class and pk. If pk is nil, false.

      Artist[1] === Artist[1] # true
      Artist.new === Artist.new # false
      Artist[1].set(:name=>'Bob') == Artist[1] # => true

         # File lib/sequel/model/base.rb, line 908
    908:       def ===(obj)
    909:         pk.nil? ? false : (obj.class == model) && (obj.pk == pk)
    910:       end

[](column) click to toggle source

Returns value of the column’s attribute.

      Artist[1][:id] #=> 1

         # File lib/sequel/model/base.rb, line 873
    873:       def [](column)
    874:         @values[column]
    875:       end

[]=(column, value) click to toggle source

Sets the value for the given column. If typecasting is enabled for this object, typecast the value based on the column’s type. If this is a new record or the typecasted value isn’t the same as the current value for the column, mark the column as changed.

      a = Artist.new
      a[:name] = 'Bob'
      a.values #=> {:name=>'Bob'}

         # File lib/sequel/model/base.rb, line 885
    885:       def []=(column, value)
    886:         # If it is new, it doesn't have a value yet, so we should
    887:         # definitely set the new value.
    888:         # If the column isn't in @values, we can't assume it is
    889:         # NULL in the database, so assume it has changed.
    890:         v = typecast_value(column, value)
    891:         if new? || !@values.include?(column) || v != (c = @values[column]) || v.class != c.class
    892:           changed_columns << column unless changed_columns.include?(column)
    893:           @values[column] = v
    894:         end
    895:       end

autoincrementing_primary_key() click to toggle source

The autoincrementing primary key for this model object. Should be overridden if you have a composite primary key with one part of it being autoincrementing.

         # File lib/sequel/model/base.rb, line 923
    923:       def autoincrementing_primary_key
    924:         primary_key
    925:       end

changed_columns() click to toggle source

The columns that have been updated. This isn’t completely accurate, as it could contain columns whose values have not changed.

      a = Artist[1]
      a.changed_columns # => []
      a.name = 'Bob'
      a.changed_columns # => [:name]

         # File lib/sequel/model/base.rb, line 934
    934:       def changed_columns
    935:         @changed_columns ||= []
    936:       end

delete() click to toggle source

Deletes and returns `self`. Does not run destroy hooks. Look into using `destroy` instead.

      Artist[1].delete # DELETE FROM artists WHERE (id = 1)
      # => #<Artist {:id=>1, ...}>

         # File lib/sequel/model/base.rb, line 943
    943:       def delete
    944:         _delete
    945:         self
    946:       end

destroy(opts = {}) click to toggle source

Like delete but runs hooks before and after delete. If before_destroy returns false, returns false without deleting the object the the database. Otherwise, deletes the item from the database and returns self. Uses a transaction if use_transactions is true or if the :transaction option is given and true.

      Artist[1].destroy # BEGIN; DELETE FROM artists WHERE (id = 1); COMMIT;
      # => #<Artist {:id=>1, ...}>

         # File lib/sequel/model/base.rb, line 957
    957:       def destroy(opts = {})
    958:         checked_save_failure(opts){checked_transaction(opts){_destroy(opts)}}
    959:       end

each(&block) click to toggle source

Iterates through all of the current values using each.

     Album[1].each{|k, v| puts "#{k} => #{v}"}
     # id => 1
     # name => 'Bob'

         # File lib/sequel/model/base.rb, line 966
    966:       def each(&block)
    967:         @values.each(&block)
    968:       end

eql?(obj) click to toggle source

Compares model instances by values.

      Artist[1] == Artist[1] # => true
      Artist.new == Artist.new # => true
      Artist[1].set(:name=>'Bob') == Artist[1] # => false

         # File lib/sequel/model/base.rb, line 975
    975:       def eql?(obj)
    976:         (obj.class == model) && (obj.values == @values)
    977:       end

errors() click to toggle source

Returns the validation errors associated with this object. See `Errors`.

         # File lib/sequel/model/base.rb, line 981
    981:       def errors
    982:         @errors ||= Errors.new
    983:       end

exists?() click to toggle source

Returns true when current instance exists, false otherwise. Generally an object that isn’t new will exist unless it has been deleted. Uses a database query to check for existence, unless the model object is new, in which case this is always false.

      Artist[1].exists? # SELECT 1 FROM artists WHERE (id = 1)
      # => true
      Artist.new.exists?
      # => false

         # File lib/sequel/model/base.rb, line 995
    995:       def exists?
    996:         new? ? false : !this.get(1).nil?
    997:       end

extend(mod) click to toggle source

Ignore the model’s setter method cache when this instances extends a module, as the module may contain setter methods.

          # File lib/sequel/model/base.rb, line 1001
    1001:       def extend(mod)
    1002:         @singleton_setter_added = true
    1003:         super
    1004:       end

hash() click to toggle source

Value that should be unique for objects with the same class and pk (if pk is not nil), or the same class and values (if pk is nil).

      Artist[1].hash == Artist[1].hash # true
      Artist[1].set(:name=>'Bob').hash == Artist[1].hash # true
      Artist.new.hash == Artist.new.hash # true
      Artist.new(:name=>'Bob').hash == Artist.new.hash # false

          # File lib/sequel/model/base.rb, line 1013
    1013:       def hash
    1014:         case primary_key
    1015:         when Array
    1016:           [model, !pk.all? ? @values.sort_by{|k,v| k.to_s} : pk].hash
    1017:         when Symbol
    1018:           [model, pk.nil? ? @values.sort_by{|k,v| k.to_s} : pk].hash
    1019:         else
    1020:           [model, @values.sort_by{|k,v| k.to_s}].hash
    1021:         end
    1022:       end

id() click to toggle source

Returns value for the :id attribute, even if the primary key is not id. To get the primary key value, use `pk`.

      Artist[1].id # => 1

          # File lib/sequel/model/base.rb, line 1028
    1028:       def id
    1029:         @values[:id]
    1030:       end

inspect() click to toggle source

Returns a string representation of the model instance including the class name and values.

          # File lib/sequel/model/base.rb, line 1034
    1034:       def inspect
    1035:         "#<#{model.name} @values=#{inspect_values}>"
    1036:       end

keys() click to toggle source

Returns the keys in `values`. May not include all column names.

      Artist.new.keys # => []
      Artist.new(:name=>'Bob').keys # => [:name]
      Artist[1].keys # => [:id, :name]

          # File lib/sequel/model/base.rb, line 1043
    1043:       def keys
    1044:         @values.keys
    1045:       end

lock!() click to toggle source

Refresh this record using `for_update` unless this is a new record. Returns self. This can be used to make sure no other process is updating the record at the same time.

      a = Artist[1]
      Artist.db.transaction do
        a.lock!
        a.update(...)
      end

          # File lib/sequel/model/base.rb, line 1056
    1056:       def lock!
    1057:         new? ? self : _refresh(this.for_update)
    1058:       end

marshallable!() click to toggle source

Remove elements of the model object that make marshalling fail. Returns self.

      a = Artist[1]
      a.marshallable!
      Marshal.dump(a)

          # File lib/sequel/model/base.rb, line 1065
    1065:       def marshallable!
    1066:         @this = nil
    1067:         self
    1068:       end

modified!() click to toggle source

Explicitly mark the object as modified, so `save_changes`/`update` will run callbacks even if no columns have changed.

      a = Artist[1]
      a.save_changes # No callbacks run, as no changes
      a.modified!
      a.save_changes # Callbacks run, even though no changes made

          # File lib/sequel/model/base.rb, line 1077
    1077:       def modified!
    1078:         @modified = true
    1079:       end

modified?() click to toggle source

Whether this object has been modified since last saved, used by save_changes to determine whether changes should be saved. New values are always considered modified.

      a = Artist[1]
      a.modified? # => false
      a.set(:name=>'Jim')
      a.modified? # => true

          # File lib/sequel/model/base.rb, line 1089
    1089:       def modified?
    1090:         @modified || !changed_columns.empty?
    1091:       end

new?() click to toggle source

Returns true if the current instance represents a new record.

      Artist.new.new? # => true
      Artist[1].new? # => false

          # File lib/sequel/model/base.rb, line 1097
    1097:       def new?
    1098:         defined?(@new) ? @new : (@new = false)
    1099:       end

pk() click to toggle source

Returns the primary key value identifying the model instance. Raises an `Error` if this model does not have a primary key. If the model has a composite primary key, returns an array of values.

      Artist[1].pk # => 1
      Artist[[1, 2]].pk # => [1, 2]

          # File lib/sequel/model/base.rb, line 1107
    1107:       def pk
    1108:         raise(Error, "No primary key is associated with this model") unless key = primary_key
    1109:         key.is_a?(Array) ? key.map{|k| @values[k]} : @values[key]
    1110:       end

pk_hash() click to toggle source

Returns a hash identifying mapping the receivers primary key column(s) to their values.

      Artist[1].pk_hash # => {:id=>1}
      Artist[[1, 2]].pk_hash # => {:id1=>1, :id2=>2}

          # File lib/sequel/model/base.rb, line 1116
    1116:       def pk_hash
    1117:         model.primary_key_hash(pk)
    1118:       end

refresh() click to toggle source

Reloads attributes from database and returns self. Also clears all changed_columns information. Raises an `Error` if the record no longer exists in the database.

      a = Artist[1]
      a.name = 'Jim'
      a.refresh
      a.name # => 'Bob'

          # File lib/sequel/model/base.rb, line 1128
    1128:       def refresh
    1129:         _refresh(this)
    1130:       end

reload() click to toggle source

Alias of refresh, but not aliased directly to make overriding in a plugin easier.

          # File lib/sequel/model/base.rb, line 1133
    1133:       def reload
    1134:         refresh
    1135:       end

save(*columns) click to toggle source

Creates or updates the record, after making sure the record is valid and before hooks execute successfully. Fails if:

- the record is not valid, or

- before_save returns false, or

- the record is new and before_create returns false, or

- the record is not new and before_update returns false.

If `save` fails and either raise_on_save_failure or the :raise_on_failure option is true, it raises ValidationFailed or HookFailed. Otherwise it returns nil.

If it succeeds, it returns self.

You can provide an optional list of columns to update, in which case it only updates those columns, or a options hash.

Takes the following options:

:changed | save all changed columns, instead of all columns or the columns given
:raise_on_failure | set to true or false to override the current `raise_on_save_failure` setting
:server | set the server/shard on the object before saving, and use that server/shard in any transaction.
:transaction | set to true or false to override the current `use_transactions` setting
:validate | set to false to skip validation

          # File lib/sequel/model/base.rb, line 1164
    1164:       def save(*columns)
    1165:         opts = columns.last.is_a?(Hash) ? columns.pop : {}
    1166:         set_server(opts[:server]) if opts[:server]
    1167:         if opts[:validate] != false
    1168:           unless checked_save_failure(opts){_valid?(true, opts)}
    1169:             raise(ValidationFailed.new(errors)) if raise_on_failure?(opts)
    1170:             return
    1171:           end
    1172:         end
    1173:         checked_save_failure(opts){checked_transaction(opts){_save(columns, opts)}}
    1174:       end

save_changes(opts={}) click to toggle source

Saves only changed columns if the object has been modified. If the object has not been modified, returns nil. If unable to save, returns false unless `raise_on_save_failure` is true.

      a = Artist[1]
      a.save_changes # => nil
      a.name = 'Jim'
      a.save_changes # UPDATE artists SET name = 'Bob' WHERE (id = 1)
      # => #<Artist {:id=>1, :name=>'Jim', ...}

          # File lib/sequel/model/base.rb, line 1185
    1185:       def save_changes(opts={})
    1186:         save(opts.merge(:changed=>true)) || false if modified?
    1187:       end

set(hash) click to toggle source

Updates the instance with the supplied values with support for virtual attributes, raising an exception if a value is used that doesn’t have a setter method (or ignoring it if `strict_param_setting = false`). Does not save the record.

      artist.set(:name=>'Jim')
      artist.name # => 'Jim'

          # File lib/sequel/model/base.rb, line 1196
    1196:       def set(hash)
    1197:         set_restricted(hash, nil, nil)
    1198:       end

set_all(hash) click to toggle source

Set all values using the entries in the hash, ignoring any setting of allowed_columns or restricted columns in the model.

      Artist.set_restricted_columns(:name)
      artist.set_all(:name=>'Jim')
      artist.name # => 'Jim'

          # File lib/sequel/model/base.rb, line 1206
    1206:       def set_all(hash)
    1207:         set_restricted(hash, false, false)
    1208:       end

set_except(hash, *except) click to toggle source

Set all values using the entries in the hash, except for the keys given in except. You should probably use `set_fields` or `set_only` instead of this method, as blacklist approaches to security are a bad idea.

      artist.set_except({:name=>'Jim'}, :hometown)
      artist.name # => 'Jim'

          # File lib/sequel/model/base.rb, line 1216
    1216:       def set_except(hash, *except)
    1217:         set_restricted(hash, false, except.flatten)
    1218:       end

set_fields(hash, fields) click to toggle source

For each of the fields in the given array `fields`, call the setter method with the value of that `hash` entry for the field. Returns self.

      artist.set_fields({:name=>'Jim'}, [:name])
      artist.name # => 'Jim'

      artist.set_fields({:hometown=>'LA'}, [:name])
      artist.name # => nil
      artist.hometown # => 'Sac'

          # File lib/sequel/model/base.rb, line 1229
    1229:       def set_fields(hash, fields)
    1230:         fields.each{|f| send("#{f}=", hash[f])}
    1231:         self
    1232:       end

set_only(hash, *only) click to toggle source

Set the values using the entries in the hash, only if the key is included in only. It may be a better idea to use `set_fields` instead of this method.

      artist.set_only({:name=>'Jim'}, :name)
      artist.name # => 'Jim'

      artist.set_only({:hometown=>'LA'}, :name) # Raise Error

          # File lib/sequel/model/base.rb, line 1242
    1242:       def set_only(hash, *only)
    1243:         set_restricted(hash, only.flatten, false)
    1244:       end

set_server(s) click to toggle source

Set the shard that this object is tied to. Returns self.

          # File lib/sequel/model/base.rb, line 1247
    1247:       def set_server(s)
    1248:         @server = s
    1249:         @this.opts[:server] = s if @this
    1250:         self
    1251:       end

set_values(hash) click to toggle source

Replace the current values with hash. Should definitely not be used with untrusted input, and should probably not be called directly by user code.

          # File lib/sequel/model/base.rb, line 1256
    1256:       def set_values(hash)
    1257:         @values = hash
    1258:       end

singleton_method_added(meth) click to toggle source

Clear the setter_methods cache when a method is added

          # File lib/sequel/model/base.rb, line 1261
    1261:       def singleton_method_added(meth)
    1262:         @singleton_setter_added = true if meth.to_s =~ SETTER_METHOD_REGEXP
    1263:         super
    1264:       end

this() click to toggle source

Returns (naked) dataset that should return only this instance.

      Artist[1].this
      # SELECT * FROM artists WHERE (id = 1) LIMIT 1

          # File lib/sequel/model/base.rb, line 1270
    1270:       def this
    1271:         @this ||= use_server(model.dataset.filter(pk_hash).limit(1).naked)
    1272:       end

update(hash) click to toggle source

Runs # with the passed hash and then runs save_changes.

      artist.update(:name=>'Jim') # UPDATE artists SET name = 'Jim' WHERE (id = 1)

          # File lib/sequel/model/base.rb, line 1277
    1277:       def update(hash)
    1278:         update_restricted(hash, nil, nil)
    1279:       end

update_all(hash) click to toggle source

Update all values using the entries in the hash, ignoring any setting of `allowed_columns` or `restricted_columns` in the model.

      Artist.set_restricted_columns(:name)
      artist.update_all(:name=>'Jim') # UPDATE artists SET name = 'Jim' WHERE (id = 1)

          # File lib/sequel/model/base.rb, line 1286
    1286:       def update_all(hash)
    1287:         update_restricted(hash, false, false)
    1288:       end

update_except(hash, *except) click to toggle source

Update all values using the entries in the hash, except for the keys given in except. You should probably use `update_fields` or `update_only` instead of this method, as blacklist approaches to security are a bad idea.

      artist.update_except({:name=>'Jim'}, :hometown) # UPDATE artists SET name = 'Jim' WHERE (id = 1)

          # File lib/sequel/model/base.rb, line 1295
    1295:       def update_except(hash, *except)
    1296:         update_restricted(hash, false, except.flatten)
    1297:       end

update_fields(hash, fields) click to toggle source

Update the instances values by calling `set_fields` with the `hash` and `fields`, then save any changes to the record. Returns self.

      artist.update_fields({:name=>'Jim'}, [:name])
      # UPDATE artists SET name = 'Jim' WHERE (id = 1)

      artist.update_fields({:hometown=>'LA'}, [:name])
      # UPDATE artists SET name = NULL WHERE (id = 1)

          # File lib/sequel/model/base.rb, line 1307
    1307:       def update_fields(hash, fields)
    1308:         set_fields(hash, fields)
    1309:         save_changes
    1310:       end

update_only(hash, *only) click to toggle source

Update the values using the entries in the hash, only if the key is included in only. It may be a better idea to use `update_fields` instead of this method.

      artist.update_only({:name=>'Jim'}, :name)
      # UPDATE artists SET name = 'Jim' WHERE (id = 1)

      artist.update_only({:hometown=>'LA'}, :name) # Raise Error

          # File lib/sequel/model/base.rb, line 1320
    1320:       def update_only(hash, *only)
    1321:         update_restricted(hash, only.flatten, false)
    1322:       end

valid?(opts = {}) click to toggle source

Validates the object and returns true if no errors are reported.

      artist(:name=>'Valid').valid? # => true
      artist(:name=>'Invalid').valid? # => false
      artist.errors.full_messages # => ['name cannot be Invalid']

          # File lib/sequel/model/base.rb, line 1338
    1338:       def valid?(opts = {})
    1339:         _valid?(false, opts)
    1340:       end

validate() click to toggle source

Validates the object. If the object is invalid, errors should be added to the errors attribute. By default, does nothing, as all models are valid by default. See the "Model Validations" guide. for details about validation. Should not be called directly by user code, call `valid?` instead to check if an object is valid.

          # File lib/sequel/model/base.rb, line 1330
    1330:       def validate
    1331:       end

### Private Instance Methods

_delete() click to toggle source

Do the deletion of the object’s dataset, and check that the row was actually deleted.

          # File lib/sequel/model/base.rb, line 1346
    1346:       def _delete
    1347:         n = _delete_without_checking
    1348:         raise(NoExistingObject, "Attempt to delete object did not result in a single row modification (Rows Deleted: #{n}, SQL: #{_delete_dataset.delete_sql})") if require_modification && n != 1
    1349:         n
    1350:       end

_delete_dataset() click to toggle source

The dataset to use when deleting the object. The same as the object’s dataset by default.

          # File lib/sequel/model/base.rb, line 1354
    1354:       def _delete_dataset
    1355:         this
    1356:       end

_delete_without_checking() click to toggle source

Actually do the deletion of the object’s dataset. Return the number of rows modified.

          # File lib/sequel/model/base.rb, line 1360
    1360:       def _delete_without_checking
    1361:         _delete_dataset.delete
    1362:       end

_destroy(opts) click to toggle source

Internal destroy method, separted from destroy to allow running inside a transaction

          # File lib/sequel/model/base.rb, line 1366
    1366:       def _destroy(opts)
    1367:         sh = {:server=>this_server}
    1368:         db.after_rollback(sh){after_destroy_rollback} if use_after_commit_rollback
    1369:         called = false
    1370:         around_destroy do
    1371:           called = true
    1372:           raise_hook_failure(:destroy) if before_destroy == false
    1373:           _destroy_delete
    1374:           after_destroy
    1375:           true
    1376:         end
    1377:         raise_hook_failure(:destroy) unless called
    1378:         db.after_commit(sh){after_destroy_commit} if use_after_commit_rollback
    1379:         self
    1380:       end

_destroy_delete() click to toggle source

Internal delete method to call when destroying an object, separated from delete to allow you to override destroy’s version without affecting delete.

          # File lib/sequel/model/base.rb, line 1385
    1385:       def _destroy_delete
    1386:         delete
    1387:       end

_insert() click to toggle source

Insert the record into the database, returning the primary key if the record should be refreshed from the database.

          # File lib/sequel/model/base.rb, line 1391
    1391:       def _insert
    1392:         ds = _insert_dataset
    1393:         if !ds.opts[:select] and ds.supports_insert_select? and h = _insert_select_raw(ds)
    1394:           @values = h
    1395:           nil
    1396:         else
    1397:           iid = _insert_raw(ds)
    1398:           # if we have a regular primary key and it's not set in @values,
    1399:           # we assume it's the last inserted id
    1400:           if (pk = autoincrementing_primary_key) && pk.is_a?(Symbol) && !@values[pk]
    1401:             @values[pk] = iid
    1402:           end
    1403:           pk
    1404:         end
    1405:       end

_insert_dataset() click to toggle source

The dataset to use when inserting a new object. The same as the model’s dataset by default.

          # File lib/sequel/model/base.rb, line 1409
    1409:       def _insert_dataset
    1410:         use_server(model.dataset)
    1411:       end

_insert_raw(ds) click to toggle source

Insert into the given dataset and return the primary key created (if any).

          # File lib/sequel/model/base.rb, line 1414
    1414:       def _insert_raw(ds)
    1415:         ds.insert(@values)
    1416:       end

_insert_select_raw(ds) click to toggle source

Insert into the given dataset and return the hash of column values.

          # File lib/sequel/model/base.rb, line 1419
    1419:       def _insert_select_raw(ds)
    1420:         ds.insert_select(@values)
    1421:       end

_refresh(dataset) click to toggle source

Refresh using a particular dataset, used inside save to make sure the same server is used for reading newly inserted values from the database

          # File lib/sequel/model/base.rb, line 1425
    1425:       def _refresh(dataset)
    1426:         set_values(_refresh_get(dataset) || raise(Error, "Record not found"))
    1427:         changed_columns.clear
    1428:         self
    1429:       end

_refresh_get(dataset) click to toggle source

Get the row of column data from the database.

          # File lib/sequel/model/base.rb, line 1432
    1432:       def _refresh_get(dataset)
    1433:         dataset.first
    1434:       end

_save(columns, opts) click to toggle source

Internal version of save, split from save to allow running inside it’s own transaction.

          # File lib/sequel/model/base.rb, line 1438
    1438:       def _save(columns, opts)
    1439:         sh = {:server=>this_server}
    1440:         db.after_rollback(sh){after_rollback} if use_after_commit_rollback
    1441:         was_new = false
    1442:         pk = nil
    1443:         called_save = false
    1444:         called_cu = false
    1445:         around_save do
    1446:           called_save = true
    1447:           raise_hook_failure(:save) if before_save == false
    1448:           if new?
    1449:             was_new = true
    1450:             around_create do
    1451:               called_cu = true
    1452:               raise_hook_failure(:create) if before_create == false
    1453:               pk = _insert
    1454:               @this = nil
    1455:               @new = false
    1456:               @was_new = true
    1457:               after_create
    1458:               true
    1459:             end
    1460:             raise_hook_failure(:create) unless called_cu
    1461:           else
    1462:             around_update do
    1463:               called_cu = true
    1464:               raise_hook_failure(:update) if before_update == false
    1465:               if columns.empty?
    1466:                 @columns_updated = if opts[:changed]
    1467:                   @values.reject{|k,v| !changed_columns.include?(k)}
    1468:                 else
    1469:                   _save_update_all_columns_hash
    1470:                 end
    1471:                 changed_columns.clear
    1472:               else # update only the specified columns
    1473:                 @columns_updated = @values.reject{|k, v| !columns.include?(k)}
    1474:                 changed_columns.reject!{|c| columns.include?(c)}
    1475:               end
    1476:               _update_columns(@columns_updated)
    1477:               @this = nil
    1478:               after_update
    1479:               true
    1480:             end
    1481:             raise_hook_failure(:update) unless called_cu
    1482:           end
    1483:           after_save
    1484:           true
    1485:         end
    1486:         raise_hook_failure(:save) unless called_save
    1487:         if was_new
    1488:           @was_new = nil
    1489:           pk ? _save_refresh : changed_columns.clear
    1490:         else
    1491:           @columns_updated = nil
    1492:         end
    1493:         @modified = false
    1494:         db.after_commit(sh){after_commit} if use_after_commit_rollback
    1495:         self
    1496:       end

_save_refresh() click to toggle source

Refresh the object after saving it, used to get default values of all columns. Separated from _save so it can be overridden to avoid the refresh.

          # File lib/sequel/model/base.rb, line 1501
    1501:       def _save_refresh
    1502:         _refresh(this.opts[:server] ? this : this.server(:default))
    1503:       end

_save_update_all_columns_hash() click to toggle source

Return a hash of values used when saving all columns of an existing object (i.e. not passing specific columns to save or using update/save_changes). Defaults to all of the object’s values except unmodified primary key columns, as some databases don’t like you setting primary key values even to their existing values.

          # File lib/sequel/model/base.rb, line 1511
    1511:       def _save_update_all_columns_hash
    1512:         v = @values.dup
    1513:         Array(primary_key).each{|x| v.delete(x) unless changed_columns.include?(x)}
    1514:         v
    1515:       end

_update(columns) click to toggle source

Update this instance’s dataset with the supplied column hash, checking that only a single row was modified.

          # File lib/sequel/model/base.rb, line 1526
    1526:       def _update(columns)
    1527:         n = _update_without_checking(columns)
    1528:         raise(NoExistingObject, "Attempt to update object did not result in a single row modification (SQL: #{_update_dataset.update_sql(columns)})") if require_modification && n != 1
    1529:         n
    1530:       end

_update_columns(columns) click to toggle source

Call _update with the given columns, if any are present. Plugins can override this method in order to update with additional columns, even when the column hash is initially empty.

          # File lib/sequel/model/base.rb, line 1520
    1520:       def _update_columns(columns)
    1521:         _update(columns) unless columns.empty?
    1522:       end

_update_dataset() click to toggle source

The dataset to use when updating an object. The same as the object’s dataset by default.

          # File lib/sequel/model/base.rb, line 1534
    1534:       def _update_dataset
    1535:         this
    1536:       end

_update_without_checking(columns) click to toggle source

Update this instances dataset with the supplied column hash.

          # File lib/sequel/model/base.rb, line 1539
    1539:       def _update_without_checking(columns)
    1540:         _update_dataset.update(columns)
    1541:       end

_valid?(raise_errors, opts) click to toggle source

Internal validation method. If `raise_errors` is `true`, hook failures will be raised as HookFailure exceptions. If it is `false`, `false` will be returned instead.

          # File lib/sequel/model/base.rb, line 1546
    1546:       def _valid?(raise_errors, opts)
    1547:         errors.clear
    1548:         called = false
    1549:         error = false
    1550:         around_validation do
    1551:           called = true
    1552:           if before_validation == false
    1553:             if raise_errors
    1554:               raise_hook_failure(:validation)
    1555:             else
    1556:               error = true
    1557:             end
    1558:             false
    1559:           else
    1560:             validate
    1561:             after_validation
    1562:             errors.empty?
    1563:           end
    1564:         end
    1565:         error = true unless called
    1566:         if error
    1567:           if raise_errors
    1568:             raise_hook_failure(:validation)
    1569:           else
    1570:             false
    1571:           end
    1572:         else
    1573:           errors.empty?
    1574:         end
    1575:       end

checked_save_failure(opts) click to toggle source

If not raising on failure, check for HookFailed being raised by yielding and swallow it.

          # File lib/sequel/model/base.rb, line 1579
    1579:       def checked_save_failure(opts)
    1580:         if raise_on_failure?(opts)
    1581:           yield
    1582:         else
    1583:           begin
    1584:             yield
    1585:           rescue HookFailed
    1586:             nil
    1587:           end
    1588:         end
    1589:       end

checked_transaction(opts={}) click to toggle source

If transactions should be used, wrap the yield in a transaction block.

          # File lib/sequel/model/base.rb, line 1592
    1592:       def checked_transaction(opts={})
    1593:         use_transaction?(opts) ? db.transaction({:server=>this_server}.merge(opts)){yield} : yield
    1594:       end

initialize_set(h) click to toggle source

Set the columns with the given hash. By default, the same as `set`, but exists so it can be overridden. This is called only for new records, before changed_columns is cleared.

          # File lib/sequel/model/base.rb, line 1599
    1599:       def initialize_set(h)
    1600:         set(h)
    1601:       end

inspect_values() click to toggle source

Default inspection output for the values hash, overwrite to change what # displays.

          # File lib/sequel/model/base.rb, line 1604
    1604:       def inspect_values
    1605:         @values.inspect
    1606:       end

raise_hook_failure(type) click to toggle source

Raise an error appropriate to the hook type. May be swallowed by checked_save_failure depending on the raise_on_failure? setting.

          # File lib/sequel/model/base.rb, line 1618
    1618:       def raise_hook_failure(type)
    1619:         raise HookFailed, "one of the before_#{type} hooks returned false"
    1620:       end

raise_on_failure?(opts) click to toggle source

Whether to raise or return false if this action fails. If the :raise_on_failure option is present in the hash, use that, otherwise, fallback to the object’s raise_on_save_failure (if set), or class’s default (if not).

          # File lib/sequel/model/base.rb, line 1612
    1612:       def raise_on_failure?(opts)
    1613:         opts.fetch(:raise_on_failure, raise_on_save_failure)
    1614:       end

set_restricted(hash, only, except) click to toggle source

Set the columns, filtered by the only and except arrays.

          # File lib/sequel/model/base.rb, line 1623
    1623:       def set_restricted(hash, only, except)
    1624:         meths = if only.nil? && except.nil? && !@singleton_setter_added
    1625:           model.setter_methods
    1626:         else
    1627:           setter_methods(only, except)
    1628:         end
    1629:         strict = strict_param_setting
    1630:         hash.each do |k,v|
    1631:           m = "#{k}="
    1632:           if meths.include?(m)
    1633:             send(m, v)
    1634:           elsif strict
    1635:             # Avoid using respond_to? or creating symbols from user input
    1636:             if public_methods.map{|s| s.to_s}.include?(m)
    1637:               if Array(model.primary_key).map{|s| s.to_s}.member?(k.to_s) && model.restrict_primary_key?
    1638:                 raise Error, "#{k} is a restricted primary key"
    1639:               else
    1640:                 raise Error, "#{k} is a restricted column"
    1641:               end
    1642:             else
    1643:               raise Error, "method #{m} doesn't exist"
    1644:             end
    1645:           end
    1646:         end
    1647:         self
    1648:       end

setter_methods(only, except) click to toggle source

Returns all methods that can be used for attribute assignment (those that end with =), modified by the only and except arguments:

- only

  - false - Don’t modify the results

  - nil - if the model has allowed_columns, use only these, otherwise, don’t modify

  - Array - allow only the given methods to be used

- except

  - false - Don’t modify the results

  - nil - if the model has restricted_columns, remove these, otherwise, don’t modify

  - Array - remove the given methods

only takes precedence over except, and if only is not used, certain methods are always restricted (RESTRICTED_SETTER_METHODS). The primary key is restricted by default as well, see Model.unrestrict_primary_key to change this.

          # File lib/sequel/model/base.rb, line 1666
    1666:       def setter_methods(only, except)
    1667:         only = only.nil? ? model.allowed_columns : only
    1668:         except = except.nil? ? model.restricted_columns : except
    1669:         if only
    1670:           only.map{|x| "#{x}="}
    1671:         else
    1672:           meths = methods.collect{|x| x.to_s}.grep(SETTER_METHOD_REGEXP) - RESTRICTED_SETTER_METHODS
    1673:           meths -= Array(primary_key).map{|x| "#{x}="} if primary_key && model.restrict_primary_key?
    1674:           meths -= except.map{|x| "#{x}="} if except
    1675:           meths
    1676:         end
    1677:       end

this_server() click to toggle source

The server/shard that the model object’s dataset uses, or :default if the model object’s dataset does not have an associated shard.

          # File lib/sequel/model/base.rb, line 1681
    1681:       def this_server
    1682:         primary_key ? (this.opts[:server] || :default) : (model.dataset.opts[:server] || :default)
    1683:       end

typecast_value(column, value) click to toggle source

Typecast the value to the column’s type if typecasting. Calls the database’s typecast_value method, so database adapters can override/augment the handling for database specific column types.

          # File lib/sequel/model/base.rb, line 1688
    1688:       def typecast_value(column, value)
    1689:         return value unless typecast_on_assignment && db_schema && (col_schema = db_schema[column])
    1690:         value = nil if value == '' and typecast_empty_string_to_nil and col_schema[:type] and ![:string, :blob].include?(col_schema[:type])
    1691:         raise(InvalidValue, "nil/NULL is not allowed for the #{column} column") if raise_on_typecast_failure && value.nil? && (col_schema[:allow_null] == false)
    1692:         begin
    1693:           model.db.typecast_value(col_schema[:type], value)
    1694:         rescue InvalidValue
    1695:           raise_on_typecast_failure ? raise : value
    1696:         end
    1697:       end

update_restricted(hash, only, except) click to toggle source

Set the columns, filtered by the only and except arrays.

          # File lib/sequel/model/base.rb, line 1700
    1700:       def update_restricted(hash, only, except)
    1701:         set_restricted(hash, only, except)
    1702:         save_changes
    1703:       end

use_server(ds) click to toggle source

Set the given dataset to use the current object’s shard.

          # File lib/sequel/model/base.rb, line 1706
    1706:       def use_server(ds)
    1707:         @server ? ds.server(@server) : ds
    1708:       end

use_transaction?(opts = {}) click to toggle source

Whether to use a transaction for this action. If the :transaction option is present in the hash, use that, otherwise, fallback to the object’s default (if set), or class’s default (if not).

          # File lib/sequel/model/base.rb, line 1713
    1713:       def use_transaction?(opts = {})
    1714:         opts.fetch(:transaction, use_transactions)
    1715:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.