I am relatively new to Rails.
I have a User model through Devise. I am wondering if it is more efficient to have all the additional fields i need for the user, in a separate Profile model.
I am coming across similar situations where I am considering creating a new model and using a has_one association to that model however it seems like maybe it will be cleaner if I had all the attributes belonging to a user within the User model. How do you deal with such situations? What effect will it have on application performance?
Can someone elaborate on the advantages and disadvantages of creating has_one relationship, especially in terms of performance.
I am also relatively new to Rails as well, but this is my take…
The benefits of associations in Rails are pretty obvious I think. In this specific case I think you are fine to go either way. Here are some things to consider…
If you use a has_one relationship, you must remember that when you are referencing the profile you will end up with something similar to this:
Simple enough, but if you wanted something like
user.first_nameyou would need to delegate that method to the Profile model. This is all a matter of preference.