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 6817093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:00:24+00:00 2026-05-26T21:00:24+00:00

1-account.rb class Account < ActiveRecord::Base belongs_to :transaction end class Supplier < Account end class

  • 0

1-account.rb

class Account < ActiveRecord::Base
    belongs_to :transaction
end

class Supplier < Account
end

class Expense < Account
end

2-transaction.rb

class Transaction < ActiveRecord::Base
    has_many :accounts
    accepts_nested_attributes_for :accounts
end

3-migration schema

create_table "accounts", :force => true do |t|
    t.string   "name"
    t.decimal  "debit"
    t.decimal  "credit"
    t.decimal  "balance"
    t.string   "type"
    t.integer  "transaction_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "transactions", :force => true do |t|
    t.string   "name"
    t.decimal  "amount"
    t.date     "date"
    t.string   "document"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end

Question1:
What’s the best method to reach supplier and expense in the view (see the picture below)?

Question2:
How can I implement a method that automatically record the transaction amount in expense_debit and supplier_credit, and vice versa? (View screenshot)

  • 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-26T21:00:25+00:00Added an answer on May 26, 2026 at 9:00 pm

    I’d suggest an alternative setup. For one thing, your transaction does not record which is the “from” account and which is the “to” account. That’s kind of important to know for later.

    I recognise that there may be multiple accounts from and to… but debit vs credit should be recorded on a per-transaction basis, not in just one big lump on the Account, otherwise it’ll be difficult later to, say, list the change in an account’s value between date A and date B (important for tax-returns or quarterly sales reports or whatever).

    i don’t know about naming, but perhaps a transaction has_many account-transfers and a transfer is “transaction_id, account_id, amount, direction” (where direction is debit/credit).

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

Sidebar

Related Questions

class Transaction < ActiveRecord::Base belongs_to :account, :polymorphic => true end class Bankaccount < ActiveRecord::Base
i have a simple associations: class Account < ActiveRecord::Base has_many :users accepts_nested_attributes_for :users validates_presence_of
I have an accounts model as follows (simplified): class Account < ActiveRecord::Base attr_accessible :account_number,
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
Here is what I'm attempting to do: class Account < ActiveRecord::Base def name end
Given these relationships: class Account < ActiveRecord::Base has_many :employments has_many :people, :through => :employments
I have an Account model and a User model: class Account < ActiveRecord::Base has_many
My models: class Contact < ActiveRecord::Base has_many :addresses has_many :emails has_many :websites accepts_nested_attributes_for :addresses,
If I have the following models setup: class Member < ActiveRecord::Base has_many :children end
In my Rails models I have: class Song < ActiveRecord::Base has_many :flags has_many :accounts,

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.