Re: Design question

Tim Lovett
Tue, 18 May 2010 13:15:42 -0000

Are customers different than users?
Can customers also be users?

I''d say you should probably just put the customers and users table into
one.
You can create a table that links off of users that links them to orders
(customers) if the need arises. Or if they are two separate roles can always
have a flag that denotes it.

The normalization is fine on the name breaking it out to its pieces.

The problem arises though when you try to break off users and customers that
if they are the same person they likely will need to reinsert all of their
previous information when signing up. It just adds messiness to the database
and makes it harder to associate their information with the user without
somehow getting the original table''s name id back to the new one. And
imagine if they have two separate name ids... then they have to go and
update their values in both tables.

I''d personally suggest you combine all three tables unless there is a
clear
distinction between customers and users,

Tim


On Tue, May 18, 2010 at 8:58 AM, pepe
<Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:

> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.