fearless_fool wrote: > I'm dipping my toe into the world of data warehousing and dimensional > databases. In: > > http://rails.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html > 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 > end > class Programmer < ActiveRecord::Base > has_many :assignments > has_many :projects, :through => :assignments > end > class Project < ActiveRecord::Base > has_many :assignments > has_many :programmers, :through => :assignments > end > -------- > So far so good -- I created empty models for these via > foreach m (Assignment Programmer Project) > script/generate model $m > end > and then went back and hand-annotated the model files as shown above. > > My questions: > > * Could ActiveRecord handle more of the model creation in this case? > If so, how?
ActiveRecord handles none of the model creation, as far as I can tell. If you're asking about whether you could have script/generate model do more, the answer is no, and you probably wouldn't want to in any case. Excessive generated code is generally a maintenance problem. > * How do I write the migration(s) to bring the db in sync with the > revised models? script/generate model already does that for you. Look in db/migrate. > * Should I implement this as three separate migrations? If it's one atomic change, then put it in one migration. One migration file should contain everything that is necessary to bring the database from one consistent state to the next consistent state. > > 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. Live up to the fearless part of your name and try it! If you have problems, please ask, but give it a try first. > > (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?) There's nothing conventionally called an "ActiveRecord descriptor". What do you mean here? And have you read the rdoc and guide on ActiveRecord associations? > > TIA. > > - ff Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.