I'm confused on what you are trying to do with FriendGroups.
Your basic Friendship is modeled as:
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => "User"
end
class User < ActiveRecord::Base
has_many :friendships
has_many :friends, :through => :friendships
end
Are you looking to mass create Friendship records between all the Users that you pass in? That's probably some sort of permutations problem. Not something you would need another model for. Maybe a class method on Friendship like interconnect(user_ids)
.
If you're wanting to find groups of Users that are all friends of each other that sounds like you're getting into Graph Theory and connectivity.
EDIT:
In the case of FriendGroups just being generic containers of friends with a name attached I would do something like this:
class User < ActiveRecord::Base
has_many :friend_groupings
has_many :friend_groups
has_many :friendships
has_many :friends, :through => :friendships
end
class FriendGrouping < ActiveRecord::Base
belongs_to :friend_group
belongs_to :friend
end
class FriendGroup < ActiveRecord::Base
has_many :friend_groupings
has_many :friends, :class_name => "User", :through => :friend_groupings
belongs_to :user
validates_presence_of :name # Name of FriendGroup
end
I would probably nest FriendGroups under Users, and have FriendGroups accept_nested_attributes_for FriendGroupings. I would do this in the FriendGroup controller and in the view for the FriendGroup allow the user to set the name of the group and then give them checkboxes for each of their friends to put in the group. For each friend they select create a new FriendGrouping between the FriendGroup and the User. That should get you what you want.