Sha256: 6c561d7c8d9db0f44641d85059db5251c28db29e779a026a5a7016adc6bf1249
Contents?: true
Size: 866 Bytes
Versions: 4
Compression:
Stored size: 866 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) end def with_user association_join(:users, select: [:name]) end end setup.mappers do define(:tasks) define(:with_user, parent: :tasks) do wrap :user do attribute :name end end end setup.relation(:users) tasks = rom.relations.tasks expect(tasks.all.with_user.to_a).to eql( [{ id: 1, name: 'Piotr', title: 'Finish ROM' }] ) expect(rom.relation(:tasks).map_with(:with_user).all.with_user.to_a).to eql( [{ id: 1, title: 'Finish ROM', user: { name: 'Piotr' } }] ) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rom-sql-0.4.3 | spec/unit/many_to_one_spec.rb |
rom-sql-0.4.1 | spec/unit/many_to_one_spec.rb |
rom-sql-0.4.0 | spec/unit/many_to_one_spec.rb |
rom-sql-0.4.0.rc1 | spec/unit/many_to_one_spec.rb |