Created
June 3, 2015 18:38
-
-
Save stravid/f6e8c648df1284c82e94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
require 'rom' | |
require 'rom-sql' | |
ROM.setup(:sql, 'postgres://localhost/datsu_development') | |
class Players < ROM::Relation[:sql] | |
register_as :players | |
dataset :players | |
def with_throws | |
inner_join(:throws, player_id: :id) | |
end | |
end | |
class Matches < ROM::Relation[:sql] | |
register_as :matches | |
dataset :matches | |
end | |
class Throws < ROM::Relation[:sql] | |
register_as :throws | |
dataset :throws | |
def for_users(users) | |
where(player_id: users.map { |user| user[:id] }) | |
end | |
end | |
ROM.finalize | |
rom = ROM.env | |
puts rom.relation(:players).to_a | |
puts '---' | |
puts rom.relation(:players).combine(rom.relation(:throws).for_users).to_a | |
puts '---' | |
puts rom.relation(:players).with_throws.to_a | |
puts '---' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment