Ruby on Rails Monday, August 31, 2015

On 31 August 2015 at 15:47, Pradeep Achuthan <pradeep83.achu@gmail.com> wrote:

I notice that the last time you asked basically the same question you
did not appear to reply or offer thanks for the help offered, which is
not good manners, unless I missed the post. However I will try to
help again. See below,

> Hi,
>
> 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.
>
> I have User, Expense, Income and UserTransaction models.
>
> Expense and Income will have following fields
>
> id, date, category, amount, description, user_id, currency

There is a big clue there. If two tables have the same fields then
almost certainly it should just be one table. Possibly call it
transactions and use different categories to distinguish between
income and expenses.

>
> I am not sure whether I need UserTransaction table also.
> But my business requirement is as follows
>
> I should be able to get all expenses/income of a user with date range and
> also with category
>
> I should also be able to get all transactions occurred with date range.

I also don't see any need for a UserTransaction table. I think you
just need User has_many transactions, Transaction belongs_to user.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtOuA-ASvoV8umXL4wiodA1xu835A-E1HHWapuO%2BsJE_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment