I'm working on application where several tables
(users,customers,other...) will have the same name structure (prefix,
first, middle, last, suffix).

I have thought about factoring out the name to a separate model:

*** Migrations ***
class CreateNames < ActiveRecord::Migration
  def self.up
    create_table :names do |t|
      t.string :prefix
      t.string :first
      t.string :middle
      t.string :suffix
    end
  end
end

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.integer   :name_id
      # other columns here
  end
end

class CreateCustomers < ActiveRecord::Migration
  def self.up
    create_table :customers do |t|
      t.integer   :name_id
      # other columns here
  end
end


*** Models ***
class Name < ActiveRecord::Base
  has_one :user
  has_one :customer
end

class User < ActiveRecord::Base
  belongs_to :name
end

class Customer < ActiveRecord::Base
  belongs_to :name
end

I believe the concept is sound but I am concerned about a couple of
things. I know that search capabilities by user/customer/other are
coming and name searches are going to be in the mix.

Am I putting myself into a bad situation by going this way?
Are named scopes going to be my friends?
What would be the best/fastest way to query the database with this
design?
Am I abstracting the DB too much?

Thanks

Pepe

-- 
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.

Reply via email to