ActiveRecord::Associations::ClassMethods
module ActiveRecord::Associations::ClassMethods
Associations are a set of macro-like class methods for tying objects together through foreign keys. They express relationships like “Project has one Project Manager” or “Project belongs to a Portfolio”. Each macro adds a number of methods to the class which are specialized according to the collection or association symbol and the options hash. It works much the same way as Ruby's own attr*
methods.
class Project < ActiveRecord::Base belongs_to :portfolio has_one :project_manager has_many :milestones has_and_belongs_to_many :categories end
The project class now has the following methods (and more) to ease the traversal and manipulation of its relationships:
登录查看完整内容