Created
July 30, 2019 17:12
-
-
Save michaelminter/6d9778b73d8b9d58e827f38dcb3fef52 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
scope :by_persons, ->(person1, person2) do | |
arel = Communication.arel_table | |
up_context1 = arel.grouping(arel[:sender_type].eq(person1.class.name).and(arel[:sender_id].eq(person1.id))) | |
dn_context1 = arel.grouping(arel[:sender_type].eq(person2.class.name).and(arel[:sender_id].eq(person2.id))) | |
up_context2 = arel.grouping(arel[:recipient_type].eq(person1.class.name).and(arel[:recipient_id].eq(person1.id))) | |
dn_context2 = arel.grouping(arel[:recipient_type].eq(person2.class.name).and(arel[:recipient_id].eq(person2.id))) | |
context1 = arel.grouping(up_context1.or(dn_context1)) | |
context2 = arel.grouping(up_context2.or(dn_context2)) | |
where(context1.and(context2)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment