Jump to content

Creating new table structure for extended user class


dgruetter

Recommended Posts

Hi. I am trying to restructure my PHP code into oop structure and now have developed an extended class called "vendor_user" from a base class "user."

 

The basic attributes in "User" will be id, email, password.

 

The extended class "vendor_user" will have vendor_id, info, phone_num, tagline, etc..

 

I was going to create two tables, one called "user" and one called "user_vendor."

 

Eventually I plan on adding another extended class "guest_user" with different attributes...

 

The way I was planning on entering vendors would be to first enter the vendor as a user and the take the id of the user table and do another insert into vendor_user using the "id" from user as a foreign key.

 

I have a few questions.

 

First, Would this be the best way to do this? My logic is all vendor_users would be users but not all users would be vendor_users.

 

Second, should I create a primary key on user_vendors (another id attribute perhaps) or should I just index the forign key vendor_id?

 

Any insights would be greatly appreciated.

 

why not have one table for all users and have a type column which can be "vendor, guest, standard, etc" ?

then you can just check the type and take the appropriate actions there. you could even combine it into a single class.

Thanks for the reply. I was actually going to include a type column, I forgot to add that. It makes sense. My question still remains on whether I should store the attributes unique to vendor in another table using the user id as a foreign key. Currently I have a foreign key in the vendor table called vendor_id (to be used for joins later in the game). But... I also have a field simply called id. This id field is the vendor tables primary id field. I was wonder if this was even needed or if I should just use the foreign key for indexing and sorting. I guess it doesn't hurt to have that extra primary key. I really need to brush up on my MYSQL skills. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.