Class: ROM::Relation

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::ClassAttributes, AutoCurry, Initializer, ClassInterface
Includes:
Memoizable, Pipeline, Materializable, Relation::Commands
Defined in:
core/lib/rom/relation.rb,
core/lib/rom/relation/name.rb,
core/lib/rom/relation/wrap.rb,
core/lib/rom/relation/graph.rb,
core/lib/rom/relation/loaded.rb,
core/lib/rom/relation/curried.rb,
core/lib/rom/relation/combined.rb,
core/lib/rom/relation/commands.rb,
core/lib/rom/relation/view_dsl.rb,
core/lib/rom/relation/composite.rb,
core/lib/rom/relation/materializable.rb,
core/lib/rom/relation/class_interface.rb

Overview

Base relation class

Relation is a proxy for the dataset object provided by the gateway. It can forward methods to the dataset, which is why the "native" interface of the underlying gateway is available in the relation

Individual adapters sets up their relation classes and provide different APIs depending on their persistence backend.

Direct Known Subclasses

Memory::Relation

Defined Under Namespace

Modules: ClassInterface, Commands, Materializable Classes: Combined, Composite, Curried, Graph, Loaded, Name, ViewDSL, Wrap

Constant Summary collapse

NOOP_OUTPUT_SCHEMA =

Default no-op output schema which is called in Relation#each

-> tuple { tuple }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__memoized__ ⇒ Object (readonly) Originally defined in module Memoizable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

#auto_map ⇒ true, false (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Whether or not a relation and its compositions should be auto-mapped.

Returns:

  • (true, false) —

    Whether or not a relation and its compositions should be auto-mapped



167
# File 'core/lib/rom/relation.rb', line 167

option :auto_map, default: -> { self.class.auto_map }

#auto_struct ⇒ true, false (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Whether or not tuples should be auto-mapped to structs.

Returns:

  • (true, false) —

    Whether or not tuples should be auto-mapped to structs



172
# File 'core/lib/rom/relation.rb', line 172

option :auto_struct, default: -> { self.class.auto_struct }

#commands ⇒ CommandRegistry (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Command registry.

Returns:



186
# File 'core/lib/rom/relation.rb', line 186

option :commands, default: -> { CommandRegistry.new({}, relation_name: name.relation) }

#dataset ⇒ Object (readonly)

Returns dataset used by the relation provided by relation's gateway.

Returns:

  • (Object) —

    dataset used by the relation provided by relation's gateway



135
# File 'core/lib/rom/relation.rb', line 135

param :dataset

#input_schema ⇒ Object#[] (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns tuple processing function, uses schema or defaults to Hash.

Returns:

  • (Object#[]) —

    tuple processing function, uses schema or defaults to Hash



154
# File 'core/lib/rom/relation.rb', line 154

option :input_schema, default: -> { schema.to_input_hash }

#mappers ⇒ MapperRegistry (readonly)

Returns an optional mapper registry (empty by default).

Returns:



181
# File 'core/lib/rom/relation.rb', line 181

option :mappers, default: -> { self.class.mapper_registry }

#meta ⇒ Hash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Meta data stored in a hash.

Returns:

  • (Hash) —

    Meta data stored in a hash



191
# File 'core/lib/rom/relation.rb', line 191

option :meta, reader: true, default: -> { EMPTY_HASH }

#name ⇒ Object (readonly)

Returns The relation name.

Returns:

  • (Object) —

    The relation name



147
148
149
# File 'core/lib/rom/relation.rb', line 147

option :name, default: lambda {
  self.class.schema ? self.class.schema.name : self.class.default_name
}

#output_schema ⇒ Object#[] (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns tuple processing function, uses schema or defaults to NOOP_OUTPUT_SCHEMA.

Returns:

  • (Object#[]) —

    tuple processing function, uses schema or defaults to NOOP_OUTPUT_SCHEMA



159
160
161
# File 'core/lib/rom/relation.rb', line 159

option :output_schema, default: lambda {
  schema.any?(&:read?) ? schema.to_output_hash : NOOP_OUTPUT_SCHEMA
}

#relation_name ⇒ Object (readonly) Originally defined in module ClassInterface

Raises:

#schema ⇒ Schema (readonly)

Returns relation schema, defaults to class-level canonical schema (if it was defined) and sets an empty one as the fallback.

Returns:

  • (Schema) —

    relation schema, defaults to class-level canonical schema (if it was defined) and sets an empty one as the fallback



142
# File 'core/lib/rom/relation.rb', line 142

option :schema, default: -> { self.class.schema || self.class.default_schema }

#schema_proc ⇒ Object (readonly) Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

#struct_namespace(ns) ⇒ Relation (readonly)

Return a new relation configured with the provided struct namespace

Parameters:

  • ns (Module) —

    Custom namespace module for auto-structs

Returns:



177
# File 'core/lib/rom/relation.rb', line 177

option :struct_namespace, reader: false, default: -> { self.class.struct_namespace }

Class Method Details

.[](adapter) ⇒ Class Originally defined in module ClassInterface

Return adapter-specific relation subclass

Examples:

ROM::Relation[:memory]
# => ROM::Memory::Relation

Returns:

  • (Class)

.auto_curried_methods ⇒ Object Originally defined in module AutoCurry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.auto_curry(name) ⇒ Object Originally defined in module AutoCurry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Auto-curry a method

Parameters:

  • name (Symbol) —

    The name of a method

.auto_curry_busy? ⇒ Boolean Originally defined in module AutoCurry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

.auto_curry_guard ⇒ Object Originally defined in module AutoCurry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.auto_map ⇒ Boolean .auto_map(value) ⇒ Object

Whether or not a relation and its compositions should be auto-mapped

Overloads:

  • .auto_map ⇒ Boolean

    Return auto_map setting value

    Returns:

    • (Boolean)
  • .auto_map(value) ⇒ Object

    Set auto_map value



82
# File 'core/lib/rom/relation.rb', line 82

defines :auto_map

.auto_struct ⇒ Boolean .auto_struct(value) ⇒ Object

Whether or not tuples should be auto-mapped to structs

Overloads:

  • .auto_struct ⇒ Boolean

    Return auto_struct setting value

    Returns:

    • (Boolean)
  • .auto_struct(value) ⇒ Object

    Set auto_struct value



93
# File 'core/lib/rom/relation.rb', line 93

defines :auto_struct

.curried ⇒ Object Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.dataset(&block) ⇒ Object Originally defined in module ClassInterface

Set or get custom dataset block

This block will be evaluated when a relation is instantiated and registered in a relation registry.

Examples:

class Users < ROM::Relation[:memory]
  dataset { sort_by(:id) }
end

.default_name ⇒ Name Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return default relation name used in schemas

Returns:

.default_schema(klass = self) ⇒ Object Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.forward(*methods) ⇒ Object Originally defined in module ClassInterface

Dynamically define a method that will forward to the dataset and wrap response in the relation itself

Examples:

class SomeAdapterRelation < ROM::Relation
  forward :super_query
end

.gateway ⇒ Symbol .gateway(gateway_key) ⇒ Object

Manage the gateway

Overloads:

  • .gateway ⇒ Symbol

    Return the gateway key that the relation is associated with

    Returns:

    • (Symbol)
  • .gateway(gateway_key) ⇒ Object

    Link the relation to a gateway. Change this setting if the relation is defined on a non-default gateway

    Examples:

    class Users < ROM::Relation[:sql]
      gateway :custom
    end

    Parameters:

    • gateway_key (Symbol)


71
# File 'core/lib/rom/relation.rb', line 71

defines :gateway

.mapper_registry(opts = EMPTY_HASH) ⇒ MapperRegistry Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build default mapper registry

Returns:

.name ⇒ Object Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.schema(dataset = nil, as: nil, infer: false) ⇒ Schema Originally defined in module ClassInterface

Specify canonical schema for a relation

With a schema defined commands will set up a type-safe input handler automatically

rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity

Examples:

class Users < ROM::Relation[:sql]
  schema do
    attribute :id, Types::Serial
    attribute :name, Types::String
  end
end

# access schema from a finalized relation
users.schema

Parameters:

  • dataset (Symbol) (defaults to: nil) —

    An optional dataset name

  • infer (Boolean) (defaults to: false) —

    Whether to do an automatic schema inferring

Returns:

.schemas ⇒ Object Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

.set_schema!(schema) ⇒ Schema Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Assign a schema to a relation class

Parameters:

Returns:

.struct_namespace ⇒ Module .struct_namespace(namespace) ⇒ Object

Get or set a namespace for auto-generated struct classes. By default, new struct classes are created within ROM::Struct

@example using custom namespace class Users < ROM::Relation struct_namespace Entities end

users.by_pk(1).one! # => #<Entities::User id=1 name="Jane Doe">

Overloads:

  • .struct_namespace ⇒ Module

    Returns Default struct namespace.

    Returns:

    • (Module) —

      Default struct namespace

  • .struct_namespace(namespace) ⇒ Object

    Parameters:

    • namespace (Module)


112
# File 'core/lib/rom/relation.rb', line 112

defines :struct_namespace

.use(plugin, **options) ⇒ Object Originally defined in module ClassInterface

Include a registered plugin in this relation class

Parameters:

  • plugin (Symbol)
  • options (Hash)

Options Hash (**options):

  • :adapter (Symbol) — default: :default —

    first adapter to check for plugin

#view(name, schema, &block) ⇒ Symbol #view(name, &block) ⇒ Symbol Originally defined in module ClassInterface

Define a relation view with a specific schema

This method should only be used in cases where a given adapter doesn't support automatic schema projection at run-time.

It's not needed in rom-sql

rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity

Overloads:

  • #view(name, schema, &block) ⇒ Symbol

    Examples:

    View with the canonical schema

    class Users < ROM::Relation[:sql]
      view(:listing, schema) do
        order(:name)
      end
    end

    View with a projected schema

    class Users < ROM::Relation[:sql]
      view(:listing, schema.project(:id, :name)) do
        order(:name)
      end
    end
  • #view(name, &block) ⇒ Symbol

    Examples:

    View with the canonical schema and arguments

    class Users < ROM::Relation[:sql]
      view(:by_name) do |name|
        where(name: name)
      end
    end

    View with projected schema and arguments

    class Users < ROM::Relation[:sql]
      view(:by_name) do
        schema { project(:id, :name) }
        relation { |name| where(name: name) }
      end
    end

    View with a schema extended with foreign attributes

    class Users < ROM::Relation[:sql]
      view(:index) do
        schema { append(relations[:tasks][:title]) }
        relation { |name| where(name: name) }
      end
    end

Returns:

  • (Symbol) —

    view method name

.view_methods ⇒ Object Originally defined in module ClassInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instance Method Details

#>>(other) ⇒ Relation::Composite Originally defined in module Pipeline::Operator

Compose two relation with a left-to-right composition

Examples:

users.by_name('Jane') >> tasks.for_users

Parameters:

  • other (Relation) —

    The right relation

Returns:

#[](name) ⇒ Attribute

Return schema attribute

Examples:

accessing canonical attribute

users[:id]
# => #<ROM::SQL::Attribute[Integer] primary_key=true
#     name=:id source=ROM::Relation::Name(users)>

accessing joined attribute

tasks_with_users = tasks.join(users).select_append(tasks[:title])
tasks_with_users[:title, :tasks]
# => #<ROM::SQL::Attribute[String] primary_key=false
#     name=:title source=ROM::Relation::Name(tasks)>

Returns:



209
# File 'core/lib/rom/relation.rb', line 209

def [](name) = schema[name]

#adapter ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The wrapped relation's adapter identifier ie :sql or :http.

Returns:

  • (Symbol) —

    The wrapped relation's adapter identifier ie :sql or :http



528
# File 'core/lib/rom/relation.rb', line 528

def adapter = self.class.adapter

#as(aliaz) ⇒ Relation

Return a new relation with an aliased name

Examples:

users.as(:people)

Parameters:

  • aliaz (Symbol) —

    Aliased name

Returns:



523
# File 'core/lib/rom/relation.rb', line 523

def as(aliaz) = with(name: name.as(aliaz))

#associations ⇒ AssociationSet

Return schema's association set (empty by default)

Returns:



442
# File 'core/lib/rom/relation.rb', line 442

def associations = schema.associations

#attr_ast ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



452
# File 'core/lib/rom/relation.rb', line 452

def attr_ast = schema.map(&:to_read_ast)

#auto_map? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


463
# File 'core/lib/rom/relation.rb', line 463

def auto_map? = (auto_map || auto_struct) && !meta[:combine_type]

#auto_struct? ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


466
# File 'core/lib/rom/relation.rb', line 466

def auto_struct? = auto_struct && !meta[:combine_type]

#call ⇒ Relation::Loaded

Loads a relation

Returns:



346
# File 'core/lib/rom/relation.rb', line 346

def call = Loaded.new(self)

#combine(*associations) ⇒ Relation #combine(*associations, **nested_associations) ⇒ Relation #combine(associations) ⇒ Relation

Combine with other relations using configured associations

Overloads:

  • #combine(*associations) ⇒ Relation

    Examples:

    users.combine(:tasks, :posts)

    Parameters:

    • *associations (Array<Symbol>) —

      A list of association names

  • #combine(*associations, **nested_associations) ⇒ Relation

    Examples:

    users.combine(:tasks, posts: :authors)

    Parameters:

    • *associations (Array<Symbol>) —

      A list of association names

    • *nested_associations (Hash) —

      A hash with nested association names

  • #combine(associations) ⇒ Relation

    Examples:

    users.combine(posts: [:authors, reviews: [:tags, comments: :author])

    Parameters:

    • *associations (Hash) —

      A hash with nested association names

Returns:



254
# File 'core/lib/rom/relation.rb', line 254

def combine(*args) = combine_with(*nodes(*args))

#combine_with(*others) ⇒ Relation::Graph

Composes with other relations

Parameters:

  • others (Array<Relation>) —

    The other relation(s) to compose with

Returns:



263
# File 'core/lib/rom/relation.rb', line 263

def combine_with(*others) = Combined.new(self, others)

#curried? ⇒ false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns if this relation is curried

Returns:

  • (false)


360
# File 'core/lib/rom/relation.rb', line 360

def curried? = false

#each {|Hash| ... } ⇒ Enumerator

Yields relation tuples

Every tuple is processed through Relation#output_schema, it's a no-op by default

Yields:

  • (Hash)

Returns:

  • (Enumerator) —

    if block is not provided



220
221
222
223
224
225
226
227
228
# File 'core/lib/rom/relation.rb', line 220

def each(&)
  return to_enum unless block_given?

  if auto_map?
    mapper.(dataset.map { |tuple| output_schema[tuple] }).each(&)
  else
    dataset.each { |tuple| yield(output_schema[tuple]) }
  end
end

#eager_load(assoc) ⇒ Relation

Return a graph node prepared by the given association

Parameters:

  • assoc (Association) —

    An association object

Returns:



299
300
301
302
303
304
305
306
307
# File 'core/lib/rom/relation.rb', line 299

def eager_load(assoc)
  relation = assoc.prepare(self)

  if assoc.override?
    relation.(assoc)
  else
    relation.preload_assoc(assoc)
  end
end

#first ⇒ Object Originally defined in module Materializable

Return first tuple from a relation coerced to an array

Returns:

  • (Object)

#foreign_key(name) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a foreign key name for the provided relation name

Parameters:

  • name (Name) —

    The relation name object

Returns:

  • (Symbol)


553
554
555
556
557
558
559
560
561
# File 'core/lib/rom/relation.rb', line 553

def foreign_key(name)
  attr = schema.foreign_key(name.dataset)

  if attr
    attr.name
  else
    :"#{Inflector.singularize(name.dataset)}_id"
  end
end

#gateway ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return name of the source gateway of this relation

Returns:

  • (Symbol)


535
# File 'core/lib/rom/relation.rb', line 535

def gateway = self.class.gateway

#graph? ⇒ false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns if this relation is a graph

Returns:

  • (false)


367
# File 'core/lib/rom/relation.rb', line 367

def graph? = false

#map_to(klass, **opts) ⇒ Relation

Return a new relation that will map its tuples to instances of the provided class

Examples:

users.map_to(MyUserModel)

Parameters:

  • klass (Class) —

    Your custom model class

Returns:



509
510
511
# File 'core/lib/rom/relation.rb', line 509

def map_to(klass, **opts)
  with(opts.merge(auto_map: false, auto_struct: true, meta: { model: klass }))
end

#map_with(*mappers) ⇒ Relation::Composite #map_with(*mappers, auto_map: true) ⇒ Relation::Composite

Maps relation with custom mappers available in the registry

When auto_map is enabled, your mappers will be applied after performing default auto-mapping. This means that you can compose complex relations and have them auto-mapped, and use much simpler custom mappers to adjust resulting data according to your requirements.

Overloads:

  • #map_with(*mappers) ⇒ Relation::Composite

    Map tuples using registered mappers

    Examples:

    users.map_with(:my_mapper, :my_other_mapper)

    Parameters:

    • mappers (Array<Symbol>) —

      A list of mapper identifiers

  • #map_with(*mappers, auto_map: true) ⇒ Relation::Composite

    Map tuples using custom registered mappers and enforce auto-mapping

    Examples:

    users.map_with(:my_mapper, :my_other_mapper, auto_map: true)

    Parameters:

    • mappers (Array<Symbol>) —

      A list of mapper identifiers

Returns:



497
# File 'core/lib/rom/relation.rb', line 497

def map_with(*names, **opts) = super(*names).with(opts)

#mapper ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



469
# File 'core/lib/rom/relation.rb', line 469

def mapper = mappers[to_ast]

#meta_ast ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



455
456
457
458
459
460
# File 'core/lib/rom/relation.rb', line 455

def meta_ast
  meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz,
                         struct_namespace: options[:struct_namespace])
  meta[:model] = false unless auto_struct? || meta[:model]
  meta
end

#new(dataset, **new_opts) ⇒ Object

Return a new relation with provided dataset and additional options

Use this method whenever you need to use dataset API to get a new dataset and you want to return a relation back. Typically relation API should be enough though. If you find yourself using this method, it might be worth to consider reporting an issue that some dataset functionality is not available through relation API.

Examples:

with a new dataset

users.new(users.dataset.some_method)

with a new dataset and options

users.new(users.dataset.some_method, other: 'options')

Parameters:

  • dataset (Object)
  • new_opts (Hash) —

    Additional options



401
402
403
404
405
406
407
408
409
410
411
412
# File 'core/lib/rom/relation.rb', line 401

def new(dataset, **new_opts)
  opts =
    if new_opts.empty?
      options
    elsif new_opts.key?(:schema)
      options.merge(new_opts).except(:input_schema, :output_schema)
    else
      options.merge(new_opts)
    end

  self.class.new(dataset, **opts)
end

#node(name) ⇒ Relation

Create a graph node for a given association identifier

Parameters:

Returns:



286
287
288
289
290
# File 'core/lib/rom/relation.rb', line 286

def node(name)
  assoc = associations[name]
  other = assoc.node
  other.eager_load(assoc)
end

#nodes(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



266
267
268
269
270
271
272
273
274
275
276
277
# File 'core/lib/rom/relation.rb', line 266

def nodes(*args)
  args.reduce([]) do |acc, arg|
    case arg
    when Symbol
      acc << node(arg)
    when Hash
      acc.concat(arg.map { |name, opts| node(name).combine(opts) })
    when Array
      acc.concat(arg.map { |opts| nodes(opts) }.reduce(:concat))
    end
  end
end

#one ⇒ Object Originally defined in module Materializable

Delegate to loaded relation and return one object

Returns:

  • (Object)

See Also:

#one! ⇒ Object Originally defined in module Materializable

Delegate to loaded relation and return one object

Returns:

  • (Object)

See Also:

#preload_assoc(assoc, other) ⇒ Relation::Curried

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Preload other relation via association

This is used internally when relations are composed

Returns:



316
# File 'core/lib/rom/relation.rb', line 316

def preload_assoc(assoc, other) = assoc.preload(self, other)

#schema? ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if a relation has schema defined

Returns:

  • (TrueClass, FalseClass)


381
# File 'core/lib/rom/relation.rb', line 381

def schema? = !schema.empty?

#schemas ⇒ Hash<Symbol=>Schema>

Return all registered relation schemas

This holds all schemas defined via view DSL

Returns:



544
# File 'core/lib/rom/relation.rb', line 544

def schemas = self.class.schemas

#to_a ⇒ Array<Hash>

Materializes a relation into an array

Returns:

  • (Array<Hash>)


353
# File 'core/lib/rom/relation.rb', line 353

def to_a = to_enum.to_a

#to_ast ⇒ Array

Returns AST for the wrapped relation

Returns:

  • (Array)


449
# File 'core/lib/rom/relation.rb', line 449

def to_ast = [:relation, [name.relation, attr_ast, meta_ast]]

#with(opts) ⇒ Relation

Returns a new instance with the same dataset but new options

Examples:

users.with(output_schema: -> tuple { .. })

Parameters:

  • opts (Hash) —

    New options

Returns:



426
427
428
429
430
431
432
433
434
435
# File 'core/lib/rom/relation.rb', line 426

def with(opts)
  new_options =
    if opts.key?(:meta)
      opts.merge(meta: meta.merge(opts[:meta]))
    else
      opts
    end

  new(dataset, **options, **new_options)
end

#wrap(*names) ⇒ Wrap

Wrap other relations using association names

Examples:

tasks.wrap(:owner)

Parameters:

  • names (Array<Symbol>) —

    A list with association identifiers

Returns:



328
329
330
# File 'core/lib/rom/relation.rb', line 328

def wrap(*names)
  wrap_around(*names.map { |n| associations[n].wrap })
end

#wrap? ⇒ false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return if this is a wrap relation

Returns:

  • (false)


374
# File 'core/lib/rom/relation.rb', line 374

def wrap? = false

#wrap_around(*others) ⇒ Relation::Wrap

Wrap around other relations

Parameters:

  • others (Array<Relation>) —

    Other relations

Returns:



339
# File 'core/lib/rom/relation.rb', line 339

def wrap_around(*others) = wrap_class.new(self, others)