Last active
May 5, 2018 23:37
-
-
Save MostlyFocusedMike/42a53de3e85923b27424b0cd55827425 to your computer and use it in GitHub Desktop.
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 BelongsToClass | |
# accessors and whatnot | |
@@all = [] | |
def initialize(has_many_class_a_obj, has_many_class_b_obj) | |
@has_many_class_a_obj = has_many_class_a_obj | |
@has_many_class_b_obj = has_many_class_b_obj | |
end | |
def self.all | |
@@all | |
end | |
end | |
class HasManyClassA | |
# ...initializations and whatnot | |
def all_belongs_to_objects | |
BelongsToClass.all.select do |belongs_to_obj| | |
belongs_to_obj.has_many_a_obj == self | |
end | |
end | |
def all_has_many_class_b_objects | |
self.all_belongs_to_objects.map do |belongs_to_obj| | |
belongs_to_obj.has_many_b_obj | |
end | |
end | |
end | |
class HasManyClassB | |
# reverse the _a_'s for _b_'s from above to get this class | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment