Rails data modelling with has_many through

I am building an expense tracker application and I am in middle of data modelling. I have a Users table. Each user will log his expenses with expense type and income with income type. So I need to know how can we set up associations for it. As per my understanding I have set it up as follows

User has_many :expenses, through: :transactions
User has_many :incomes, through: :transactions

Expense belongs_to :user

Income belongs_to :user

Here I am not sure what the transaction would associate and also expene/income type.

Any suggestions/insights would be great.

What are the fields of expense and income? The answer to that determines whether you need a transactions table and what should be in it.

Colin

Pradeep, following pertains to more advanced folks here. I thought that demonstrating a good solution would be easy, but I am encountering LocalJumpError: no block given (yield) on transaction_id… I created a transaction table, and referenced it from User has_many. Folks, what the problem there? Liz

Pradeep, following pertains to more advanced folks here. I thought that demonstrating a good solution would be easy, but I am encountering LocalJumpError: no block given (yield) on transaction_id... I created a transaction table, and referenced it from User has_many. Folks, what the problem there?

Transaction is a reserved word (for database transactions oddly enough). Change the model name.

Colin

t 19, 2015 at 1:06:46 AM UTC-4, Pradeep Achuthan wrote:

Pradeep, following pertains to more advanced folks here. I thought that demonstrating a good solution would be easy, but I am encountering LocalJumpError: no block given (yield) on transaction_id... I created a transaction table, and referenced it from User has_many. Folks, what the problem there?

Transaction is a reserved word (for database transactions oddly enough). Change the model name.

I put this site up years ago, when I was first learning Rails: https://reservedwords.herokuapp.com

I am sure it could use some updating, but it is mostly accurate...

Walter

Okay… I have prepared the following…

First thing is that you need to know a bit about accounting. Accounting involves a (debit/credit) ledger that delineates all business aspects of income, expenses, …

So to build a web site with tables based on each of these is not, in my opinion, a good idea.

So I offer the following:

Build the tables:

Thanks Colin and Walter for contribution… Liz

Forgot:

class User < ActiveRecord::Base

has_many :user_transaction

end