### Home Classes Methods

### In Files

- lib/sequel/model/associations.rb

### Methods

- #_apply_association_options
- #_associated_dataset
- #_dataset
- #_join_table_dataset
- #_load_associated_objects
- #_refresh
- #add_associated_object
- #add_reciprocal_object
- #array_uniq!
- #associations
- #ensure_associated_primary_key
- #load_associated_objects
- #pk_or_nil
- #remove_all_associated_objects
- #remove_associated_object
- #remove_check_existing_object_from_pk
- #remove_reciprocal_object
- #run_association_callbacks
- #set_associated_object
- #set_one_to_one_associated_object

### 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::Associations::InstanceMethods

Instance methods used to implement the associations support.

### Public Instance Methods

associations() click to toggle source

The currently cached associations. A hash with the keys being the association name symbols and the values being the associated object or nil (many_to_one), or the array of associated objects (*_to_many).

          # File lib/sequel/model/associations.rb, line 1373
    1373:         def associations
    1374:           @associations ||= {}
    1375:         end

pk_or_nil() click to toggle source

Formally used internally by the associations code, like pk but doesn’t raise an Error if the model has no primary key. Not used any longer, deprecated.

          # File lib/sequel/model/associations.rb, line 1379
    1379:         def pk_or_nil
    1380:           key = primary_key
    1381:           key.is_a?(Array) ? key.map{|k| @values[k]} : @values[key]
    1382:         end

### Private Instance Methods

_apply_association_options(opts, ds) click to toggle source

Apply the association options such as :order and :limit to the given dataset, returning a modified dataset.

          # File lib/sequel/model/associations.rb, line 1387
    1387:         def _apply_association_options(opts, ds)
    1388:           ds.extend(AssociationDatasetMethods)
    1389:           ds.model_object = self
    1390:           ds.association_reflection = opts
    1391:           opts[:extend].each{|m| ds.extend(m)}
    1392:           ds = ds.select(*opts.select) if opts.select
    1393:           if c = opts[:conditions]
    1394:             ds = (c.is_a?(Array) && !Sequel.condition_specifier?(c)) ? ds.filter(*c) : ds.filter(c)
    1395:           end
    1396:           ds = ds.order(*opts[:order]) if opts[:order]
    1397:           ds = ds.limit(*opts[:limit]) if opts[:limit]
    1398:           ds = ds.limit(1) if !opts.returns_array? && opts[:key]
    1399:           ds = ds.eager(*opts[:eager]) if opts[:eager]
    1400:           ds = ds.distinct if opts[:distinct]
    1401:           ds = ds.eager_graph(opts[:eager_graph]) if opts[:eager_graph] && opts.eager_graph_lazy_dataset?
    1402:           ds = send(opts.dataset_helper_method, ds) if opts[:block]
    1403:           ds
    1404:         end

_associated_dataset(opts, dynamic_opts) click to toggle source

Return a dataset for the association after applying any dynamic callback.

          # File lib/sequel/model/associations.rb, line 1407
    1407:         def _associated_dataset(opts, dynamic_opts)
    1408:           ds = send(opts.dataset_method)
    1409:           if callback = dynamic_opts[:callback]
    1410:             ds = callback.call(ds)
    1411:           end
    1412:           ds
    1413:         end

_dataset(opts) click to toggle source

Return an association dataset for the given association reflection

          # File lib/sequel/model/associations.rb, line 1416
    1416:         def _dataset(opts)
    1417:           raise(Sequel::Error, "model object #{inspect} does not have a primary key") if opts.dataset_need_primary_key? && !pk
    1418:           _apply_association_options(opts, send(opts._dataset_method))
    1419:         end

_join_table_dataset(opts) click to toggle source

Dataset for the join table of the given many to many association reflection

          # File lib/sequel/model/associations.rb, line 1422
    1422:         def _join_table_dataset(opts)
    1423:           ds = model.db.from(opts.join_table_source)
    1424:           opts[:join_table_block] ? opts[:join_table_block].call(ds) : ds
    1425:         end

_load_associated_objects(opts, dynamic_opts={}) click to toggle source

Return the associated objects from the dataset, without association callbacks, reciprocals, and caching. Still apply the dynamic callback if present.

          # File lib/sequel/model/associations.rb, line 1429
    1429:         def _load_associated_objects(opts, dynamic_opts={})
    1430:           if opts.returns_array?
    1431:             opts.can_have_associated_objects?(self) ? _associated_dataset(opts, dynamic_opts).all : []
    1432:           else
    1433:             if opts.can_have_associated_objects?(self)
    1434:               _associated_dataset(opts, dynamic_opts).all.first
    1435:             end
    1436:           end
    1437:         end

_refresh(dataset) click to toggle source

Clear the associations cache when refreshing

          # File lib/sequel/model/associations.rb, line 1440
    1440:         def _refresh(dataset)
    1441:           associations.clear
    1442:           super
    1443:         end

add_associated_object(opts, o, *args) click to toggle source

Add the given associated object to the given association

          # File lib/sequel/model/associations.rb, line 1446
    1446:         def add_associated_object(opts, o, *args)
    1447:           klass = opts.associated_class
    1448:           if o.is_a?(Hash)
    1449:             o = klass.new(o)
    1450:           elsif o.is_a?(Integer) || o.is_a?(String) || o.is_a?(Array)
    1451:             o = klass[o]
    1452:           elsif !o.is_a?(klass)
    1453:             raise(Sequel::Error, "associated object #{o.inspect} not of correct type #{klass}")
    1454:           end
    1455:           raise(Sequel::Error, "model object #{inspect} does not have a primary key") unless pk
    1456:           ensure_associated_primary_key(opts, o, *args)
    1457:           return if run_association_callbacks(opts, :before_add, o) == false
    1458:           send(opts._add_method, o, *args)
    1459:           if array = associations[opts[:name]] and !array.include?(o)
    1460:             array.push(o)
    1461:           end
    1462:           add_reciprocal_object(opts, o)
    1463:           run_association_callbacks(opts, :after_add, o)
    1464:           o
    1465:         end

add_reciprocal_object(opts, o) click to toggle source

Add/Set the current object to/as the given object’s reciprocal association.

          # File lib/sequel/model/associations.rb, line 1468
    1468:         def add_reciprocal_object(opts, o)
    1469:           return unless reciprocal = opts.reciprocal
    1470:           if opts.reciprocal_array?
    1471:             if array = o.associations[reciprocal] and !array.include?(self)
    1472:               array.push(self)
    1473:             end
    1474:           else
    1475:             o.associations[reciprocal] = self
    1476:           end
    1477:         end

array_uniq!(a) click to toggle source

Call uniq! on the given array. This is used by the :uniq option, and is an actual method for memory reasons.

          # File lib/sequel/model/associations.rb, line 1481
    1481:         def array_uniq!(a)
    1482:           a.uniq!
    1483:         end

ensure_associated_primary_key(opts, o, *args) click to toggle source

Save the associated object if the associated object needs a primary key and the associated object is new and does not have one. Raise an error if the object still does not have a primary key

          # File lib/sequel/model/associations.rb, line 1488
    1488:         def ensure_associated_primary_key(opts, o, *args)
    1489:           if opts.need_associated_primary_key?
    1490:             o.save(:validate=>opts[:validate]) if o.new?
    1491:             raise(Sequel::Error, "associated object #{o.inspect} does not have a primary key") unless o.pk
    1492:           end
    1493:         end

load_associated_objects(opts, dynamic_opts=nil) click to toggle source

Load the associated objects using the dataset, handling callbacks, reciprocals, and caching.

          # File lib/sequel/model/associations.rb, line 1496
    1496:         def load_associated_objects(opts, dynamic_opts=nil)
    1497:           if dynamic_opts == true or dynamic_opts == false or dynamic_opts == nil
    1498:             dynamic_opts = {:reload=>dynamic_opts}
    1499:           elsif dynamic_opts.respond_to?(:call)
    1500:             dynamic_opts = {:callback=>dynamic_opts}
    1501:           end
    1502:           if block_given?
    1503:             dynamic_opts = dynamic_opts.merge(:callback=>Proc.new)
    1504:           end
    1505:           name = opts[:name]
    1506:           if associations.include?(name) and !dynamic_opts[:callback] and !dynamic_opts[:reload]
    1507:             associations[name]
    1508:           else
    1509:             objs = _load_associated_objects(opts, dynamic_opts)
    1510:             if opts.set_reciprocal_to_self?
    1511:               if opts.returns_array?
    1512:                 objs.each{|o| add_reciprocal_object(opts, o)}
    1513:               elsif objs
    1514:                 add_reciprocal_object(opts, objs)
    1515:               end
    1516:             end
    1517:             associations[name] = objs
    1518:             run_association_callbacks(opts, :after_load, objs)
    1519:             associations[name]
    1520:           end
    1521:         end

remove_all_associated_objects(opts, *args) click to toggle source

Remove all associated objects from the given association

          # File lib/sequel/model/associations.rb, line 1524
    1524:         def remove_all_associated_objects(opts, *args)
    1525:           raise(Sequel::Error, "model object #{inspect} does not have a primary key") unless pk
    1526:           send(opts._remove_all_method, *args)
    1527:           ret = associations[opts[:name]].each{|o| remove_reciprocal_object(opts, o)} if associations.include?(opts[:name])
    1528:           associations[opts[:name]] = []
    1529:           ret
    1530:         end

remove_associated_object(opts, o, *args) click to toggle source

Remove the given associated object from the given association

          # File lib/sequel/model/associations.rb, line 1533
    1533:         def remove_associated_object(opts, o, *args)
    1534:           klass = opts.associated_class
    1535:           if o.is_a?(Integer) || o.is_a?(String) || o.is_a?(Array)
    1536:             o = remove_check_existing_object_from_pk(opts, o, *args)
    1537:           elsif !o.is_a?(klass)
    1538:             raise(Sequel::Error, "associated object #{o.inspect} not of correct type #{klass}")
    1539:           elsif opts.remove_should_check_existing? && send(opts.dataset_method).filter(o.pk_hash).empty?
    1540:             raise(Sequel::Error, "associated object #{o.inspect} is not currently associated to #{inspect}")
    1541:           end
    1542:           raise(Sequel::Error, "model object #{inspect} does not have a primary key") unless pk
    1543:           raise(Sequel::Error, "associated object #{o.inspect} does not have a primary key") if opts.need_associated_primary_key? && !o.pk
    1544:           return if run_association_callbacks(opts, :before_remove, o) == false
    1545:           send(opts._remove_method, o, *args)
    1546:           associations[opts[:name]].delete_if{|x| o === x} if associations.include?(opts[:name])
    1547:           remove_reciprocal_object(opts, o)
    1548:           run_association_callbacks(opts, :after_remove, o)
    1549:           o
    1550:         end

remove_check_existing_object_from_pk(opts, o, *args) click to toggle source

Check that the object from the associated table specified by the primary key is currently associated to the receiver. If it is associated, return the object, otherwise raise an error.

          # File lib/sequel/model/associations.rb, line 1555
    1555:         def remove_check_existing_object_from_pk(opts, o, *args)
    1556:           key = o
    1557:           pkh = opts.associated_class.qualified_primary_key_hash(key)
    1558:           raise(Sequel::Error, "no object with key(s) #{key.inspect} is currently associated to #{inspect}") unless o = send(opts.dataset_method).first(pkh)
    1559:           o
    1560:         end

remove_reciprocal_object(opts, o) click to toggle source

Remove/unset the current object from/as the given object’s reciprocal association.

          # File lib/sequel/model/associations.rb, line 1563
    1563:         def remove_reciprocal_object(opts, o)
    1564:           return unless reciprocal = opts.reciprocal
    1565:           if opts.reciprocal_array?
    1566:             if array = o.associations[reciprocal]
    1567:               array.delete_if{|x| self === x}
    1568:             end
    1569:           else
    1570:             o.associations[reciprocal] = nil
    1571:           end
    1572:         end

run_association_callbacks(reflection, callback_type, object) click to toggle source

Run the callback for the association with the object.

          # File lib/sequel/model/associations.rb, line 1575
    1575:         def run_association_callbacks(reflection, callback_type, object)
    1576:           raise_error = raise_on_save_failure || !reflection.returns_array?
    1577:           stop_on_false = [:before_add, :before_remove, :before_set].include?(callback_type)
    1578:           reflection[callback_type].each do |cb|
    1579:             res = case cb
    1580:             when Symbol
    1581:               send(cb, object)
    1582:             when Proc
    1583:               cb.call(self, object)
    1584:             else
    1585:               raise Error, "callbacks should either be Procs or Symbols"
    1586:             end
    1587:             if res == false and stop_on_false
    1588:               raise(BeforeHookFailed, "Unable to modify association for #{inspect}: one of the #{callback_type} hooks returned false") if raise_error
    1589:               return false
    1590:             end
    1591:           end
    1592:         end

set_associated_object(opts, o) click to toggle source

Set the given object as the associated object for the given many_to_one association reflection

          # File lib/sequel/model/associations.rb, line 1595
    1595:         def set_associated_object(opts, o)
    1596:           raise(Error, "associated object #{o.inspect} does not have a primary key") if o && !o.pk
    1597:           run_association_callbacks(opts, :before_set, o)
    1598:           if a = associations[opts[:name]]
    1599:             remove_reciprocal_object(opts, a)
    1600:           end
    1601:           send(opts._setter_method, o)
    1602:           associations[opts[:name]] = o
    1603:           add_reciprocal_object(opts, o) if o
    1604:           run_association_callbacks(opts, :after_set, o)
    1605:           o
    1606:         end

set_one_to_one_associated_object(opts, o) click to toggle source

Set the given object as the associated object for the given one_to_one association reflection

          # File lib/sequel/model/associations.rb, line 1609
    1609:         def set_one_to_one_associated_object(opts, o)
    1610:           raise(Error, "object #{inspect} does not have a primary key") unless pk
    1611:           run_association_callbacks(opts, :before_set, o)
    1612:           if a = associations[opts[:name]]
    1613:             remove_reciprocal_object(opts, a)
    1614:           end
    1615:           send(opts._setter_method, o)
    1616:           associations[opts[:name]] = o
    1617:           add_reciprocal_object(opts, o) if o
    1618:           run_association_callbacks(opts, :after_set, o)
    1619:           o
    1620:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.