### Home Classes Methods

### In Files

- lib/sequel/model/base.rb

### Methods

- ::new
- #==
- #===
- #[]
- #[]=
- #autoincrementing_primary_key
- #changed_columns
- #delete
- #destroy
- #each
- #eql?
- #errors
- #exists?
- #hash
- #id
- #inspect
- #keys
- #lock!
- #marshallable!
- #modified!
- #modified?
- #new?
- #pk
- #pk_hash
- #refresh
- #reload
- #save
- #save_changes
- #set
- #set_all
- #set_except
- #set_fields
- #set_only
- #this
- #update
- #update_all
- #update_except
- #update_fields
- #update_only
- #valid?
- #validate

### Files

- CHANGELOG
- COPYING
- README.rdoc
- advanced_associations.rdoc
- association_basics.rdoc
- cheat_sheet.rdoc
- dataset_basics.rdoc
- dataset_filtering.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.2.0.txt
- 3.3.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
- sharding.rdoc
- sql.rdoc
- virtual_rows.rdoc

### Class/Module Index

Quicksearch

- Sequel
- Sequel::ADO
- Sequel::ADO::Database
- Sequel::ADO::Dataset
- Sequel::ADO::MSSQL
- Sequel::ADO::MSSQL::DatabaseMethods
- Sequel::ADO::MSSQL::Dataset
- Sequel::AdapterNotFound
- Sequel::Amalgalite
- Sequel::Amalgalite::Database
- Sequel::Amalgalite::Dataset
- Sequel::Amalgalite::SequelTypeMap
- Sequel::BasicObject
- Sequel::BeforeHookFailed
- Sequel::ConnectionPool
- Sequel::ConnectionPool::ClassMethods
- Sequel::DB2
- Sequel::DB2::Database
- Sequel::DB2::Dataset
- 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::ArgumentMapper
- Sequel::Dataset::Pagination
- Sequel::Dataset::PreparedStatementMethods
- Sequel::Dataset::QueryBlockCopy
- Sequel::Dataset::StoredProcedureMethods
- Sequel::Dataset::StoredProcedures
- Sequel::Dataset::UnnumberedArgumentMapper
- Sequel::Error
- Sequel::Error::AdapterNotFound
- Sequel::Error::InvalidOperation
- Sequel::Error::InvalidValue
- Sequel::Error::PoolTimeoutError
- Sequel::Error::Rollback
- Sequel::Firebird
- Sequel::Firebird::Database
- Sequel::Firebird::Dataset
- Sequel::Inflections
- Sequel::Informix
- Sequel::Informix::Database
- Sequel::Informix::Dataset
- Sequel::IntegerMigrator
- Sequel::InvalidOperation
- Sequel::InvalidValue
- Sequel::JDBC
- Sequel::JDBC::AS400
- Sequel::JDBC::AS400::DatabaseMethods
- Sequel::JDBC::AS400::Dataset
- Sequel::JDBC::Database
- Sequel::JDBC::Dataset
- Sequel::JDBC::Dataset::PreparedStatementMethods
- Sequel::JDBC::Dataset::StoredProcedureMethods
- Sequel::JDBC::H2
- Sequel::JDBC::H2::DatabaseMethods
- Sequel::JDBC::H2::Dataset
- Sequel::JDBC::JavaLang
- Sequel::JDBC::JavaSQL
- Sequel::JDBC::JavaxNaming
- Sequel::JDBC::MSSQL
- Sequel::JDBC::MSSQL::DatabaseMethods
- Sequel::JDBC::MSSQL::Dataset
- 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::SQLite
- Sequel::JDBC::SQLite::DatabaseMethods
- Sequel::JDBC::SQLite::Dataset
- Sequel::LiteralString
- Sequel::LooserTypecasting
- Sequel::MSSQL
- Sequel::MSSQL::DatabaseMethods
- Sequel::MSSQL::DatasetMethods
- Sequel::Metaprogramming
- Sequel::Migration
- Sequel::MigrationDSL
- Sequel::Migrator
- Sequel::Migrator::Error
- Sequel::Model
- Sequel::Model::Associations
- Sequel::Model::Associations::AssociationDatasetMethods
- Sequel::Model::Associations::AssociationReflection
- Sequel::Model::Associations::ClassMethods
- Sequel::Model::Associations::DatasetMethods
- 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::Database
- Sequel::MySQL::DatabaseMethods
- Sequel::MySQL::Dataset
- Sequel::MySQL::Dataset::CallableStatementMethods
- Sequel::MySQL::Dataset::PreparedStatementMethods
- Sequel::MySQL::Dataset::StoredProcedureMethods
- Sequel::MySQL::DatasetMethods
- Sequel::NamedTimezones
- Sequel::NoExistingObject
- Sequel::NotImplemented
- Sequel::ODBC
- 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::Dataset
- Sequel::Oracle::DatasetMethods
- Sequel::Plugins
- Sequel::Plugins::ActiveModel
- Sequel::Plugins::ActiveModel::InstanceMethods
- Sequel::Plugins::AssociationDependencies
- Sequel::Plugins::AssociationDependencies::ClassMethods
- Sequel::Plugins::AssociationDependencies::InstanceMethods
- Sequel::Plugins::AssociationPks
- Sequel::Plugins::AssociationPks::ClassMethods
- 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::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::LazyAttributes
- Sequel::Plugins::LazyAttributes::ClassMethods
- Sequel::Plugins::LazyAttributes::InstanceMethods
- Sequel::Plugins::ManyThroughMany
- Sequel::Plugins::ManyThroughMany::ClassMethods
- 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::RcteTree
- Sequel::Plugins::Schema
- Sequel::Plugins::Schema::ClassMethods
- Sequel::Plugins::Serialization
- Sequel::Plugins::Serialization::ClassMethods
- Sequel::Plugins::Serialization::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::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::PoolTimeout
- Sequel::Postgres
- Sequel::Postgres::Adapter
- Sequel::Postgres::AdapterMethods
- Sequel::Postgres::Database
- Sequel::Postgres::DatabaseMethods
- Sequel::Postgres::Dataset
- Sequel::Postgres::Dataset::ArgumentMapper
- Sequel::Postgres::Dataset::BindArgumentMethods
- Sequel::Postgres::Dataset::PreparedStatementMethods
- Sequel::Postgres::DatasetMethods
- Sequel::Postgres::DatasetMethods::PreparedStatementMethods
- Sequel::PrettyTable
- Sequel::Progress
- Sequel::Progress::DatabaseMethods
- Sequel::Progress::DatasetMethods
- 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::SQLArray
- Sequel::SQL::StringConcatenationMethods
- Sequel::SQL::StringExpression
- Sequel::SQL::StringMethods
- Sequel::SQL::Subscript
- Sequel::SQL::SubscriptMethods
- Sequel::SQL::VirtualRow
- Sequel::SQL::Window
- Sequel::SQL::WindowFunction
- Sequel::SQLite
- Sequel::SQLite::Database
- Sequel::SQLite::DatabaseMethods
- Sequel::SQLite::Dataset
- Sequel::SQLite::Dataset::ArgumentMapper
- Sequel::SQLite::Dataset::PreparedStatementMethods
- Sequel::SQLite::DatasetMethods
- Sequel::Schema
- Sequel::Schema::AlterTableGenerator
- Sequel::Schema::Generator
- Sequel::ShardedSingleConnectionPool
- Sequel::ShardedThreadedConnectionPool
- Sequel::SimpleMigration
- Sequel::SingleConnectionPool
- Sequel::ThreadLocalTimezones
- Sequel::ThreadedConnectionPool
- Sequel::TimestampMigrator
- Sequel::Timezones
- Sequel::ValidationFailed
- 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 create instance methods that are called by Sequel when the appropriate action occurs. For example, when destroying a model object, Sequel 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, dataset, db, primary_key, db_schema.

- The following instance methods allow boolean flags to be set on a per-object basis: raise_on_save_failure, raise_on_typecast_failure, require_modification, strict_param_setting, typecast_empty_string_to_nil, typecast_on_assignment, use_transactions. If they are not used, the object will default to whatever the model setting is.

### Attributes

values[R]

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

### 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 - should only be set by Model.load, forget it exists.

    # File lib/sequel/model/base.rb, line 555
    def initialize(values = {}, from_db = false)
      if from_db
        @new = false
        set_values(values)
      else
        @values = {}
        @new = true
        @modified = true
        set(values)
        changed_columns.clear
        yield self if block_given?
      end
      after_initialize
    end

### Public Instance Methods

==(obj) click to toggle source

Alias of eql?

    # File lib/sequel/model/base.rb, line 592
    def ==(obj)
      eql?(obj)
    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.

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

[](column) click to toggle source

Returns value of the column’s attribute.

    # File lib/sequel/model/base.rb, line 571
    def [](column)
      @values[column]
    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 a a new record or the typecasted value isn’t the same as the current value for the column, mark the column as changed.

    # File lib/sequel/model/base.rb, line 579
    def []=(column, value)
      # If it is new, it doesn't have a value yet, so we should
      # definitely set the new value.
      # If the column isn't in @values, we can't assume it is
      # NULL in the database, so assume it has changed.
      v = typecast_value(column, value)
      if new? || !@values.include?(column) || v != @values[column]
        changed_columns << column unless changed_columns.include?(column)
        @values[column] = v
      end
    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 611
    def autoincrementing_primary_key
      primary_key
    end

changed_columns() click to toggle source

The columns that have been updated. This isn’t completely accurate, see Model#[]=.

    # File lib/sequel/model/base.rb, line 617
    def changed_columns
      @changed_columns ||= []
    end

delete() click to toggle source

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

    # File lib/sequel/model/base.rb, line 623
    def delete
      _delete
      self
    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.

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

each(&block) click to toggle source

Iterates through all of the current values using each.

Example:

    Ticket.find(7).each { |k, v| puts "#{k} => #{v}" }

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

eql?(obj) click to toggle source

Compares model instances by values.

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

errors() click to toggle source

Returns the validation errors associated with this object.

    # File lib/sequel/model/base.rb, line 652
    def errors
      @errors ||= Errors.new
    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.

    # File lib/sequel/model/base.rb, line 659
    def exists?
      this.count > 0
    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).

    # File lib/sequel/model/base.rb, line 665
    def hash
      [model, pk.nil? ? @values.sort_by{|k,v| k.to_s} : pk].hash
    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.

    # File lib/sequel/model/base.rb, line 671
    def id
      @values[:id]
    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 677
    def inspect
      "#<#{model.name} @values=#{inspect_values}>"
    end

keys() click to toggle source

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

    # File lib/sequel/model/base.rb, line 682
    def keys
      @values.keys
    end

lock!() click to toggle source

Refresh this record using for_update unless this is a new record. Returns self.

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

marshallable!() click to toggle source

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

    # File lib/sequel/model/base.rb, line 692
    def marshallable!
      @this = nil
      self
    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.

    # File lib/sequel/model/base.rb, line 699
    def modified!
      @modified = true
    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.

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

new?() click to toggle source

Returns true if the current instance represents a new record.

    # File lib/sequel/model/base.rb, line 711
    def new?
      @new
    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.

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

pk_hash() click to toggle source

Returns a hash identifying the model instance. It should be true that:

    Model[model_instance.pk_hash] === model_instance

    # File lib/sequel/model/base.rb, line 726
    def pk_hash
      model.primary_key_hash(pk)
    end

refresh() click to toggle source

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

    # File lib/sequel/model/base.rb, line 733
    def refresh
      _refresh(this)
    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 738
    def reload
      refresh
    end

save(*columns) click to toggle source

Creates or updates the record, after making sure the record is valid. If the record is not valid, or before_save, before_create (if new?), or before_update (if !new?) return false, returns nil unless raise_on_save_failure is true (if it is true, it raises an error). Otherwise, returns self. You can provide an optional list of columns to update, in which case it only updates those columns.

Takes the following options:

- :changed - save all changed columns, instead of all columns or the columns given

- :transaction - set to false not to use a transaction

- :validate - set to false not to validate the model before saving

    # File lib/sequel/model/base.rb, line 755
    def save(*columns)
      opts = columns.last.is_a?(Hash) ? columns.pop : {}
      if opts[:validate] != false and !valid?
        raise(ValidationFailed.new(errors)) if raise_on_save_failure
        return
      end
      checked_save_failure{checked_transaction(opts){_save(columns, opts)}}
    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.

    # File lib/sequel/model/base.rb, line 767
    def save_changes(opts={})
      save(opts.merge(:changed=>true)) || false if modified?
    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.

    # File lib/sequel/model/base.rb, line 775
    def set(hash)
      set_restricted(hash, nil, nil)
    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.

    # File lib/sequel/model/base.rb, line 781
    def set_all(hash)
      set_restricted(hash, false, false)
    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.

    # File lib/sequel/model/base.rb, line 787
    def set_except(hash, *except)
      set_restricted(hash, false, except.flatten)
    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.

    # File lib/sequel/model/base.rb, line 793
    def set_fields(hash, fields)
      fields.each{|f| send("#{f}=", hash[f])}
      self
    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.

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

this() click to toggle source

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

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

update(hash) click to toggle source

Runs set with the passed hash and then runs save_changes.

    # File lib/sequel/model/base.rb, line 810
    def update(hash)
      update_restricted(hash, nil, nil)
    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.

    # File lib/sequel/model/base.rb, line 816
    def update_all(hash)
      update_restricted(hash, false, false)
    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.

    # File lib/sequel/model/base.rb, line 822
    def update_except(hash, *except)
      update_restricted(hash, false, except.flatten)
    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.

    # File lib/sequel/model/base.rb, line 828
    def update_fields(hash, fields)
      set_fields(hash, fields)
      save_changes
    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.

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

valid?() click to toggle source

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

    # File lib/sequel/model/base.rb, line 847
    def valid?
      errors.clear
      if before_validation == false
        save_failure(:validation) if raise_on_save_failure
        return false
      end
      validate
      after_validation
      errors.empty?
    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.

    # File lib/sequel/model/base.rb, line 843
    def validate
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.