hcarreras
hcarreras

Reputation: 4612

User profile. Should I create a new model?

this is basically a theoretical question. What do you think is better for a normal rails app with users:

1)Create a Profile model where to put resume, images, links etc...

2)Put all the data in the user model.

The first choice maybe is cleaner but you have to load 2 models from the db, so maybe slower.

Thanks in advance.

Upvotes: 0

Views: 65

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176372

I normally have a single User model. If I have unrelated resources that may deserve an associated model, than I create one for them.

For example, for me the Resume (assuming is not a single field) may deserve a dedicated Resume model, with a one-to-one association to User.

On the view, I normally create an /account resource that internally displays the account and provides the show, edit and update actions to view the account or update it.

The more models you have, the more your architecture will become complicated. So unless you have the need to split the fields out of the User model, I would keep them inside the model.

When you start to have several fields that may require a prefix, such as resume_title, resume_body, resume_created_at inside the User model, that's a good indication that you probably need a separate Resume model associated to the User.

Upvotes: 3

Related Questions