Created
January 16, 2010 00:19
-
-
Save elskwid/278538 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 Search < ActiveRecord::Base | |
has_many :search_results | |
has_many :cars, :through => :search_results, :source => :results, :source_type => "Car" | |
has_many :dealers, :through => :search_results, :source => :results, :source_type => "Dealer" | |
# search.results gives you the list of linked records | |
has_many :results, :class_name => "SearchResult" | |
end | |
class SearchResult < ActiveRecord::Base | |
belongs_to :search | |
# can be polymorphically linked to anything that is a resultant | |
belongs_to :results, :polymorphic => true | |
end | |
class Car < ActiveRecord::Base | |
# cars can be results | |
has_many :search_results, :as => :results | |
# -> car.searches gets you the list of searches | |
has_many :searches, :through => :search_results | |
end | |
class Dealer < ActiveRecord::Base | |
# dealers can be results | |
has_many :search_results, :as => :results | |
# -> dealer.searches gets you the list of searches | |
has_many :searches, :through => :search_results | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment