So far I've spent a day trying to model the following, which I believe should be simple, I've looked at it too much, and there is probably an obvious solution staring at me..
Objective: Users
book clients
onto events
which can be chargeable, users access cashbox
area to account for payments for those chargeable events
(money in), other_charges
(money in)but only related to clients) and record general expenses
(money out)unrelated to events or clients).
So far: User, Client and Event model created with correct associations. Typical scenario; user books client onto event, that can be chargeable (boolean).
# == Associations so far
class User < ActiveRecord::Base
has_many :clients
has_many :events
end
class Client < ActiveRecord::Base
has_one :user, through: :events
has_many :events
end
class Event < ActiveRecord::Base
belongs_to :user
belongs_to :client
end
Problem: Should the associations for cashbox
be polymorphic or has_many :through?
They way I understand it using polymorphic; events, other_charges & expenses could be cashboxable
. The downside to this is I understand I can't sum
over polymorphic associations?
With has_many through I am confused how to associate this, it seems complicated. But I could be missing something.