# Modeling Users in Battle-Game App?

**URL:** <https://www.ruby-forum.com/t/modeling-users-in-battle-game-app/183687>\
**Category:** Rails\
**Created:** [February 18, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/modeling-users-in-battle-game-app/183687 "2010-02-18T18:38:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![audreylee88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@audreylee88](https://www.ruby-forum.com/u/audreylee88)\
**Post date:** [February 18, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/modeling-users-in-battle-game-app/183687/1 "2010-02-18T18:38:59Z")

</div>

Dear List,

I’d welcome some opinions on a modeling challenge I have.

I’m working on a game-app.

Each user in this app has many friends.

Also the user has many enemies.

These friends and enemies are user objects.

So we have 2 possible HABTM (Has And Belongs To Many) relationships.

A user HABTM friends.  
A user HABTM enemies.

But, I dont like HABTM.

I’d prefer to have a HMT (Has Many Through).

I think it might be typical that when I replace a HABTM with a HMT,  
that I use a model with “Membership” in its name.

So for example, I might Have-Many-Friends in England.

So perhaps I’d have a FriendsLocationMembership model.

Or, I might Have-Many-Enemies because I am a mutant.

So it looks like a Membership model could have an attribute name  
“reason” which helps me understand why a particular user might be my  
enemy or friend.

So it seems reasonable that I might have 2 or 3 groups of friends for  
different reasons:

- I have money
- I am a good warrior
- I am trustworthy  
etc…

Obviously the same goes for my enemies.

Also another question I need to answer is related to battles.

In any battle I’d like to know who are my friends and who are my  
enemies.

And of course if I see a friend/enemy I want to know who his friends  
and enemies are.

I’m looking for help/ideas on how I might code up the associations in  
the models and the syntax in the migrations.

What makes this difficult for me is I only see 2 models:

User  
Membership

Or possibly 3 models:

User  
FriendMembership  
EnemyMembership

Do any of you think this is an interesting topic?

–Audrey
