How to handle Profile Informations with :has_many_through?

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 … .

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.

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?

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.

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
[email protected]

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?

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
[email protected]

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
[email protected]