# How to handle Profile Informations with :has\_many\_through?

**URL:** <https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477>\
**Category:** Rails\
**Created:** [January 12, 2010, 3:34pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477 "2010-01-12T15:34:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 3:34pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/1 "2010-01-12T15:34:20Z")

</div>

Hi,

i try to implement a Profile System for the users into my Rails App.  
i want to implement it with these models:

class Profile \< ActiveRecord::Base  
has\_many :Profileships  
has\_many :users, :through =\> :Profileships

# GehÃ¶rt zu einer Profil Gruppe

belongs\_to :profile\_group  
end

class Profileship \< ActiveRecord::Base  
belongs\_to :user  
belongs\_to :Profile  
end

class ProfileGroup \< ActiveRecord::Base

# Eine Profil Gruppe hat mehrere Profile

has\_many :profiles  
end

So a user can edit his Profile informations of a Profile group, stored  
in the Profileship Database(there is a value fieldin the Profileship  
table).  
Do you think this is a good solution, or should i manage the Profile  
informations in one model and avoid the :has\_many\_through thing?  
How should i handle the views, because i think i have to setup a view  
for every Profilegroup, because i cant build them dynamical, because i  
can’t figure out if a information needs a input or a textare or … .

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 5:05pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/2 "2010-01-12T17:05:04Z")

</div>

What you have setup there is a Many to Many association. Is that  
really what you want? Can one profile belong to multiple users?

If you give us a better understanding of your end goal we may be able  
to help more.

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 5:34pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/3 "2010-01-12T17:34:56Z")

</div>

Thats right, because every User has the same profile fields , the  
possible Profile fields are saved in the Profile model.  
The value of a profile field of one user is saved in the Profileship  
model in the field “value”.  
So how can i put that in a view based on the Profilegroup?

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 7:08pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/4 "2010-01-12T19:08:35Z")

</div>

So, for example there are profile field for work, main profile fields,  
contact field (msn, email, adress…) and so.  
So i think there is usage for the user.

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 5:50pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/5 "2010-01-12T17:50:54Z")

</div>

LeonS wrote:

> Thats right, because every User has the same profile fields , the  
> possible Profile fields are saved in the Profile model.  
> The value of a profile field of one user is saved in the Profileship  
> model in the field “value”.  
> So how can i put that in a view based on the Profilegroup?

What on earth are you trying to achieve? What is a profile group for?

How do you want this to work from the user’s perspective?

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 8:42pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/6 "2010-01-12T20:42:50Z")

</div>

Let me explain Why i Write the Models:  
i’m Coming from Database Development, so normalization is very  
Important for me.  
If i create just a Profile Model and put all possible profile Fields  
into that, than there is no normalization  
Should i avoid the normalization in Case of RoR and keep the Models  
assimple As possible?

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 7:17pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/7 "2010-01-12T19:17:25Z")

</div>

LeonS wrote:

> So, for example there are profile field for work, main profile fields,  
> contact field (msn, email, adress…) and so

These could all be in the User model or, failing that, in a separate  
Profile model where User has\_one :profile. Why do you need Profileship  
and ProfileGroup?

> So i think there is usage for the user.

Not as far as you’ve explained. Please explain more clearly if I’ve  
missed something.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [January 12, 2010, 9:12pm UTC](https://www.ruby-forum.com/t/how-to-handle-profile-informations-with-has-many-through/181477/8 "2010-01-12T21:12:27Z")

</div>

LeonS wrote:

> Let me explain Why i Write the Models:  
> i’m Coming from Database Development, so normalization is very  
> Important for me.

To me too.

> If i create just a Profile Model and put all possible profile Fields  
> into that, than there is no normalization

Of course there is. Won’t every user have the same set of profile  
fields?

If not, what is your use case? No theory for the moment, just an actual  
example.

> Should i avoid the normalization in Case of RoR and keep the Models  
> assimple As possible?

No, you should normalize without overcomplicating.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
