Created
March 9, 2019 13:59
-
-
Save igkuz/a2803d02dfd78f71e54f79affe59ca1a to your computer and use it in GitHub Desktop.
ROM Relations for Post & Company
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
class Companies < ROM::Relation[:sql] | |
schema(:companies, infer: true) do | |
associations do | |
has_many :posts | |
end | |
end | |
end |
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
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