I’m dipping my toe into the world of data warehousing and dimensional
I was excited to find the following under the “many to many” section
– it’s the pattern I’m looking for:
class Assignment < ActiveRecord::Base
belongs_to :programmer # foreign key - programmer_id
belongs_to :project # foreign key - project_id
class Programmer < ActiveRecord::Base
has_many :projects, :through => :assignments
class Project < ActiveRecord::Base
has_many :programmers, :through => :assignments
So far so good – I created empty models for these via
foreach m (Assignment Programmer Project)
script/generate model $m
and then went back and hand-annotated the model files as shown above.
- Could ActiveRecord handle more of the model creation in this case?
If so, how?
- How do I write the migration(s) to bring the db in sync with the
- Should I implement this as three separate migrations?
The guide in http://guides.rubyonrails.org/migrations.html shows an
example (grep ExampleMigration), but I’m not feeling sure footed
enough to try it unchaperoned.
(As an aside, is there some nifty reference that shows the mapping
between ActiveRecord descriptors and the equivalent SQL? Or should I
dig through the sources to figure that out?)