Skip to content

Instantly share code, notes, and snippets.

@TalkativeTree
Last active December 31, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TalkativeTree/8000502 to your computer and use it in GitHub Desktop.
Save TalkativeTree/8000502 to your computer and use it in GitHub Desktop.
models for an api that returns search results for terms from different search engines/apis.
class SearchEngine < ActiveRecord::Base
has_and_belongs_to_many :terms
has_many :searches, through: :terms
end
class Term < ActiveRecord::Base
has_and_belongs_to_many :searches
has_and_belongs_to_many :searche_engines
end
class Result < ActiveRecord::Base
belongs_to :source
has_many :rankings
has_many :searches, through: :rankings
end
class Source < ActiveRecord::Base
has_many :results
end
class Ranking < ActiveRecord::Base
belongs_to :search
belongs_to :result
end
class Search < ActiveRecord::Base
has_many :rankings
has_many :results, through: :rankings
has_and_belongs_to_many :terms
has_many :search_engines, through :terms
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment