Hello everyone,
I am looking to split my code from one “god” relation into related relations.
The split would help reliability and composability.
I will use an example with Animals, Classifications, and Categories.
class Animals < ROM::Relation[:sql]
schema(:animals, infer: true) do
associations do
belongs_to :classifications
end
end
def level_one_animals
# Here join classification with categories level 1
end
end
class Classifications < ROM::Relation[:sql]
schema(:classifications, infer: true) do
associations do
belongs_to :categories
end
end
def with_categories_level(level)
# Here join categories for level
end
end
class Categories < ROM::Relation[:sql]
schema(:categories, infer: true)
def for_level(level)
where(level: level)
end
end
How may Animals join Classification and Categories, without knowing anything about Categories?
Thanks !