Sha256: 07f08d8b59ed6d1272077999d3417e5aa0bbd6ad8697a7e3c7acb3c297534b30

Contents?: true

Size: 595 Bytes

Versions: 3

Compression:

Stored size: 595 Bytes

Contents

require 'spec_helper'

describe 'Defining many-to-one association' do
  include_context 'users and tasks'

  it 'extends relation with association methods' do
    setup.relation(:tasks) do
      many_to_one :users, key: :user_id

      def all
        select(:id, :title).rename(title: :task_title).qualified
      end

      def with_user
        association_join(:users, select: [:name])
      end
    end

    setup.relation(:users)

    tasks = rom.relations.tasks

    expect(tasks.all.with_user.to_a).to eql(
      [{ id: 1, user_name: 'Piotr', task_title: 'Finish ROM' }]
    )
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-sql-0.2.0 spec/unit/many_to_one_spec.rb
rom-sql-0.1.1 spec/unit/many_to_one_spec.rb
rom-sql-0.1.0 spec/unit/many_to_one_spec.rb