Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:48:13+00:00 2026-05-30T09:48:13+00:00

I am currently developing a Dungeons & Dragons 4th Edition Character Sheet application in

  • 0

I am currently developing a Dungeons & Dragons 4th Edition Character Sheet application in Ruby on Rails 3.2.1. I am currently at a stage where I realize that I need to associate character races (dwarves, elves, …) with ability bonuses. (Example: a dwarf gets +2 bonuses to the Constitution and Wisdom abilities as a racial trait.)

I currently have the following set up:

class Character < ActiveRecord::Base {
  has_many :attributions
  has_many :abilities, through: :attributions
}

class Attribution < ActiveRecord::Base {
  belongs_to :character
  belongs_to :ability

  # The "attributions" table also has the column "score,"
  # which is the character's ability score
}

class Ability < ActiveRecord::Base {
  has_many :attributions
  has_many :characters, through: :attributions
}

As you can see, the characters each have their own set of abilities. I figure I may do the same thing for character races, but I am unsure of any best practices in this area. I could probably use the same join model, creating something like this (Character would stay the same, except for an overridden abilities method, perhaps):

class CharacterRace < ActiveRecord::Base {
  # I am not sure if this will actually work, but I hope
  # you understand what I am trying to do with this
  has_many :racial_ability_traits, class_name: "Attribution"
  has_many :abilities, through: :racial_ability_traits
}

class Attribution < ActiveRecord::Base {
  # The following two are just like before
  belongs_to :character
  belongs_to :ability

  # This field would be new
  belongs_to :character_class
}

class Ability < ActiveRecord::Base {
  # These are the same as above
  has_many :attributions
  has_many :characters, through: :attributions

  # These would be new, and I am not sure if it will work, but
  # I hope you understand what I amm trying to do with this
  has_many :racial_traits, class_name: "Attribution"
  has_many :character_races, through: :racial_ability_traits
}

However, even if this would work, I somehow feel like having the same join model for different joins (even if the purpose is pretty much the same) is kind of an ugly approach. I could, of course, create a different kind of join like this:

class CharacterRace < ActiveRecord::Base {
  has_many :abilities, through: :attributions

  # These are for the racial bonus
  has_many :racial_ability_bonuses
  has_many :abilities, through: :racial_ability_bonuses
}

class RacialAbilityBonus < ActiveRecord::Base {
  belongs_to :character_race
  belongs_to :ability
}

class Ability < ActiveRecord::Base {
  has_many :attributions
  has_many :abilities, through: :attributions

  # These are for the racial bonus
  has_many :racial_ability_bonuses
  has_many :character_races, through: :racial_ability_bonuses
}

This would probably work, but there is a problem. Not only the races can have such traits/bonuses. A magical item might also give an ability bonus. Therefore, an Item model should also be given a has_many :abilities, through: :item_ability_bonus association. Continuing down the road explained above, this would cause a lot of join models.

I am therefore asking you guys if you know any good approach for handling this problem. Any suggestion about making my existing code better is welcome as well.

I am very thankful for all of your serious answers. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:48:14+00:00Added an answer on May 30, 2026 at 9:48 am

    I think you just need polymorphic associations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing a Rails application using a database that was designed before
I'm currently developing a PHP application that's using an Access database as a backend.
I'm currently developing an application that is comprised of five separate executables that communicate
Im currently developing a Silverlight application that connects to an old webservice. Our old
I’m currently developing an application that will be heavy on images, that I hope
Currently developing an application for Windows Phone that makes use of the bing maps
I currently developing a web based application for a client. the requirement given that
Im currently developing an application that needs to store a 10 to 20 digit
I am currently developing an application that uses LDAP to add/read users to the
I am currently developing a Lithium application and have come across a function that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.