Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Last active April 27, 2017 19:29
Show Gist options
  • Save flash-gordon/96020d4c21a0ad7754f56b6b6c983efd to your computer and use it in GitHub Desktop.
Save flash-gordon/96020d4c21a0ad7754f56b6b6c983efd 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