schema.rb naming conventions

going by <http://wiki.rubyonrails.org/rails/pages/

, I think that I have my table names in the schema

squared away, but I'm not convinced. For a many-to-many with ThroughAssociations between tables foo and bar, is the join table created named foo_bars by convention? If the table name is foo_bars, then the corresponding model in app/models would be FooBar, is that right?

If FooBar is created by me, then, going by the comments in schema.rb, a migration command was the correct way to create the schema.

I'm just not convinced that I'm following convention on this.

C:\code\strawr\db> C:\code\strawr\db> C:\code\strawr\db>type schema.rb # This file is autogenerated. Instead of editing this file, please use the # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition.

ActiveRecord::Schema.define(:version => 3) do

  create_table "categories", :force => true do |t|     t.column "category", :string, :default => "NULL"   end

  create_table "category_feeds", :force => true do |t|     t.column "category_id", :integer, :default => 0     t.column "feed_id", :integer, :default => 0   end

  create_table "feeds", :force => true do |t|     t.column "feed", :string, :default => "NULL"   end

end

C:\code\strawr\db>

thanks,

Thufir

Going by <http://grover.open2space.com/node/138&gt;, the corresponding model would CustomerOrder, is that right?

thanks,

Thufir

And I've come across this a few different ways:

Many-to-many

There are two ways to build a many-to-many relationship.

The first way uses a has_many association with the :through option and a join model, so there are two stages of associations.

  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

<http://api.rubyonrails.com/classes/ActiveRecord/Associations/ ClassMethods.html>

In that example, the name for the join model doesn't contain the models which it joins. I also saw a similar naming scheme in the rails recipe book, I believe. Aaaargh.

-Thufir

If you want to use has_many/through, then you should try to come up with a meaningful name for the relationship. If you are connecting foos to bars, I would only call the relationship table bars_foos if I were going to use has_and_belongs_to_many.

Even though it's now out of fashion, I see no reason not to use habtm for relationships with no data. If some data appears later, just rename the table and add some columns.