Ruby on Rails Thursday, January 31, 2013

On 31 January 2013 16:01, Nishan T. <> wrote:
> I'm migrating the tables with existing data
> I've users table and all other tables contains the user_id column and
> now i need seperate the users into two (users & customers) tables
> So i need to migrate the new customers table with existing users records
> where the user type with customer

Are you sure you want to do it that way? It may well be simpler to
keep one table with flags to indicate the type of the user.
Alternatively you could use STI (though again this may be more complex
than just flags). Also there is the cancan gem that allows users to
have various roles (user and customer in this case). Remember that
you can have multiple relationships between the same tables with
different association names for the different cases. Also remember
that you can have self-referential associations so that if you want
relationships between users and customers that can still be done even
if they are in the same table. See the Rails Guide on ActiveRecord

If you can't see how this would work post the proposed relationships
between users, customers and the rest for suggestions on how to
achieve the same thing with a single table.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
For more options, visit

No comments:

Post a Comment