Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov
Forked from flash-gordon/relation-example.rb
Created April 27, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v-kolesnikov/856020266cd2564970a3d8b2dd1c07df to your computer and use it in GitHub Desktop.
Save v-kolesnikov/856020266cd2564970a3d8b2dd1c07df to your computer and use it in GitHub Desktop.
class Jobs < ROM::Relation[:sql]
schema(:jobs) do
# ...
associations do
belongs_to :team
belongs_to :template
belongs_to :address
belongs_to :client
end
end
view(:index) do
schema do
append(
relations[:references][:code].as(:type_code),
relations[:teams][:name].as(:team_name),
relations[:templates][:name].as(:template_name),
relations[:addresses][:formatted].as(:formatted_address),
relations[:clients][:name].as(:client_name)
).qualified
end
relation do |tenant_id|
where(self[:tenant_id].qualified.is(tenant_id))
.left_join(teams)
.left_join(templates)
.left_join(addresses)
.left_join(clients)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment