Created
May 4, 2018 15:32
-
-
Save flash-gordon/276a5cef6f9646bfb08caa0c40bcbe79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Templates < ROM::Relation[:sql] | |
schema do | |
attribute :possible_resolution_ids, Types::PG::Array('bigint') | |
associations do | |
has_many :resolutions, | |
as: :possible_resolutions, | |
relation: :resolutions, | |
view: :for_possible_resolutions_in_templates, | |
foreign_key: :template_id, | |
override: true | |
end | |
end | |
end | |
class Resolutions < ROM::Relation[:sql] | |
def for_possible_resolutions_in_templates(_assoc, templates) | |
template_id = templates.pluck(:template_id)[0] | |
select_append { int::cast(`'#{ template_id }'`, 'bigint').as(:template_id) }. | |
where(resolution_id: templates.pluck(:possible_resolution_ids).flatten(1)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment