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
English: a User manages many Listings, and a Listing is managed by many Users. The association is handled by ListingManager via listing_id and manager_id as foreign keys. | |
In the examples, below notice how one can create willy-nilly method names for the association as long as one defines how to get from one side of the association to the other. Another take away: the info for class_name and foreign_key and source are handled as literal strings for the purposes of the method constructing its SQL behind the scenes; it's only where Rails cannot infer the naming that one has to help out a bit | |
class ListingManager < ActiveRecord::Base | |
belongs_to :listing | |
belongs_to :manager, class_name:"User" | |
belongs_to :cato, class_name:"User", foreign_key: "manager_id" | |
end |