Skip to content

Instantly share code, notes, and snippets.

@acook
Last active December 16, 2015 10:19
Show Gist options
  • Save acook/5419116 to your computer and use it in GitHub Desktop.
Save acook/5419116 to your computer and use it in GitHub Desktop.
class Element
include DataMapper::Resource
property :id, Serial
property :name, String
end
class Composition
include DataMapper::Resource
property :id, Serial
belongs_to :primary_element_id, 'Element'
belongs_to :secondary_element_id, 'Element'
belongs_to :result_element_id, 'Element'
def self.find_by_elements element1, element2
all(primary_element_id: element1.id, secondary_element_id: element2.id) |
all(primary_element_id: element2.id, secondary_element_id: element1.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment