Skip to content

Instantly share code, notes, and snippets.

@igkuz
Created March 9, 2019 13:59
Show Gist options
  • Save igkuz/a2803d02dfd78f71e54f79affe59ca1a to your computer and use it in GitHub Desktop.
Save igkuz/a2803d02dfd78f71e54f79affe59ca1a to your computer and use it in GitHub Desktop.
ROM Relations for Post & Company
class Companies < ROM::Relation[:sql]
schema(:companies, infer: true) do
associations do
has_many :posts
end
end
end
class Posts < ROM::Relation[:sql]
schema(:posts, infer: true) do
attribute :stats, Types::Coercible::JSON
associations do
belongs_to :company
end
end
def by_url(url)
where(url: url).to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment