Sha256: 529ccde91b7184cbecb8b3b7a94e191f78b42e1bd5f70327d646ec01111b3661

Contents?: true

Size: 980 Bytes

Versions: 21

Compression:

Stored size: 980 Bytes

Contents

RSpec.describe 'Eager loading' do
  include_context 'users and tasks'

  with_adapters do
    before do
      conf.relation(:users) do
        def by_name(name)
          where(name: name)
        end
      end

      conf.relation(:tasks) do
        def for_users(users)
          where(user_id: users.map { |tuple| tuple[:id] })
        end
      end

      conf.relation(:tags) do
        def for_tasks(tasks)
          inner_join(:task_tags, task_id: :id)
            .where(task_id: tasks.map { |tuple| tuple[:id] })
        end
      end
    end

    it 'issues 3 queries for 3 combined relations' do
      users = container.relation(:users).by_name('Piotr')
      tasks = container.relation(:tasks)
      tags = container.relation(:tags)

      relation = users.combine(tasks.for_users.combine(tags.for_tasks))

      # TODO: figure out a way to assert correct number of issued queries
      expect(relation.call).to be_instance_of(ROM::Relation::Loaded)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rom-sql-1.3.3 spec/integration/combine_spec.rb
rom-sql-1.3.2 spec/integration/combine_spec.rb
rom-sql-1.3.1 spec/integration/combine_spec.rb
rom-sql-1.3.0 spec/integration/combine_spec.rb
rom-sql-1.2.2 spec/integration/combine_spec.rb
rom-sql-1.2.1 spec/integration/combine_spec.rb
rom-sql-1.2.0 spec/integration/combine_spec.rb
rom-sql-1.1.2 spec/integration/combine_spec.rb
rom-sql-1.1.1 spec/integration/combine_spec.rb
rom-sql-1.1.0 spec/integration/combine_spec.rb
rom-sql-1.0.3 spec/integration/combine_spec.rb
rom-sql-1.0.2 spec/integration/combine_spec.rb
rom-sql-1.0.1 spec/integration/combine_spec.rb
rom-sql-1.0.0 spec/integration/combine_spec.rb
rom-sql-1.0.0.rc2 spec/integration/combine_spec.rb
rom-sql-1.0.0.rc1 spec/integration/combine_spec.rb
rom-sql-1.0.0.beta3 spec/integration/combine_spec.rb
rom-sql-1.0.0.beta2 spec/integration/combine_spec.rb
rom-sql-1.0.0.beta1 spec/integration/combine_spec.rb
rom-sql-0.9.1 spec/integration/combine_spec.rb