views:

119

answers:

6

Hello,

I'm building Rails application and I want to have user registration/login functionality. I also need to have other fields in the User's model such address(street, city, country), facebook info, twitter info, last login time...etc

From a design perspective, is it better to have the User model very light-weight and have just username/password/email info and leave the other fields for separate model such as "profile", or is it better to combine those things together?

I care mostly about performance.

Thanks,

Tam

+1  A: 

I would say put them together. I think you would just be creating more work for yourself without a gain significant enough to justify it if you split up the info like that.

Authlogic is probably the nicest plugin for dealing with authentication if you are looking for one. It recognizes some of the fields you are interested in (like last login etc) and fills in automagically. A list is on their site.

Mike Williamson
+1  A: 

Keep it all in the same model, it's simpler in the beginning, avoids premature optimization, and you can always introduce another model if it's really necessary.

Leonid Shevtsov
+1  A: 

I'd agree definitely keep it in one Model. Should you have to expand/remove from the User model later it'll cut down on your work. More importantly, if you design your User model well enough, you may not even have the need for an additional "Profile" model, since most of the logic/description for a user is contained within the original User model. You could then simply create Profile or "Accounts" controller that exposes the pieces of the User model you deem neccessary. First decide if you absolute need a "Profile" object and go from there. If not you can still create one but save down on the need to create another model to maintain.

Nick L
+1  A: 

Single model recommended here as well, along with using Authlogic. Fantastic library.

Bob Martens
+1  A: 

Up until now I have always used restful_authentication, with a few tweaks it's always been fine so far, but I do really need to have a play with Authlogic.

As far as the others' answers go I can see their points of view, simplicity is often very beneficial, but I disagree that the out and out right answer is to put all that information in your user model. I would consider your application in general, how many models are you likely to have in total, how many of those will need addresses for example? Straight away I would be very tempted to move the address at least into a separate model.

Personally I believe its better to start with normalized tables then maybe evaluate de-normalizing if you can justify the performance gains. Remember you are probably going to be loading the user object frequently, if you do achieve a high login rate that bloated model could become a source for improvement, which later down the line could be harder to do than now.

As with most things it's a trade off that needs to be answered in each set of circumstances. I hope a different insight is of some use, I just think you should consider the other side of the coin too, hope that helps.

tsdbrown
+1  A: 

Another vote for the same model. If you are thinking about performance you are probably writing your own select query's etc so in my eyes it doesn't really matter how skinny or fat the model is in your case.

Bitterzoet