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

  • Home
  • SEARCH
  • 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 6097335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:01:53+00:00 2026-05-23T13:01:53+00:00

I currently have a model for an assignment table in Rails 3, which looks

  • 0

I currently have a model for an assignment table in Rails 3, which looks as follows (there are, of course, sale and financeCompany models also):

class SaleFinanceCompany < ActiveRecord::Base
  attr_accessible :sale_id, :financeCompany_id, :financedBalance

  belongs_to :sale
  belongs_to :financeCompany
end

My question is simple: how can I set up the sale/financeCompany models so that I can access the associated financedBalance?

For example, in my view I would like to have:

<% for financeCo in sale.financeCompanies %>
    <%= "£" + financeCo.financedBalance + " from "%>
    <%= financeCo.name %>
<% end %>

That unfortunately does not work, with the error being the financedBalance part. The only way I could see to set up my finance company model would be with a

has_many :financedBalances, :through => :saleFinanceCompanies

but this will give me several financedBalances for each sale, but I need one (each financedBalance is tied to both a sale and finance company in the assignment table, so doing sale.financedBalances.where etc. would seem unnecessary when I should be able to do sale.financeCompany.financedBalance).

Any suggestions?

  • 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-23T13:01:54+00:00Added an answer on May 23, 2026 at 1:01 pm

    Rails treats join tables a bit differently than you might think. From a DBA perspective, your join table is perfectly fine but for Rails true join tables have only referential columns. As soon as you add a new column, Rails likes to treat the join table as a new entity.

    (On a personal note, I was frustrated by this at first but I quickly learned it’s not a big deal)

    So, to fix your problem, you’ll need to rename your table, let’s say FinanceBalances. Also, let’s change financedBalance to amount.

    Then, in your Sale.rb file put you associations like so:

    has_many :financeBalances
    has_many :financeCompanies, :through => :financeBalances
    

    Do the same for FinanceCompany.

    And your code will look like:

    <% for financeBalance in sale.financeBalances %>
      <%= "£" + financeBalance.amount + " from " %>
      <%= financeBalance.financeCompany.name %>
    <% end %>
    

    If you really really want financeCompany.financedBalance to work, you can define a method in your financeCompany model and write the query that returns what you want.

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

Sidebar

Related Questions

I'm building an app in Rails 3. I currently have a user model which
I have a data model in Doctrine/symfony. I have a 'Course' which has many
I currently have a cardType attribute on my entity, which in the old model
I currently have a Rails app in which users of different ranks can upload
I have an Auction model with several attributes, two of which are current_auction:boolean and
I currently have a functioning in-house Windows Forms application which extensively uses the DataGridView
I have a project which exposes object model to use by different types of
I currently have a model that the user can upload a thumbnail to the
I currently have a bookings model such as: public class RoomBooking : Entity, IBooking
I'm new to SQLAlchemy. I currently have: ev = model.EnumerationValue(key=key_level_2, code=level_2) ev.keyvalues[key_parent] = level_1

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.