Suppose the following data schema:
Usage
======
client_id
resource
type
amount
Billing
======
client_id
usage_resource
usage_type
rate
In this example, suppose I have multiple resources, each of which can be used in many ways. For example, one resource is a widget
. Widgets
can be foo
ed and they can be bar
ed. Gizmo
s can also be foo
ed and bar
ed. These usage types are billed at different rates, possibly even different rates for different clients. Each occurence of a usage (of a resource) is recorded in the Usage table. Each billing rate (for client, resource, and type combination) is stored in the billing table.
(By the way, if this data schema is not the right way to approach this problem, please make suggestions.)
Is it possible, using Ruby on Rails and ActiveRecord, to create a has_many
relationship from Billings to Usages so that I can get a list of usage instances for a given billing rate? Is there a syntax of the has_many, :through
that I don't know?
Once again, I may be approaching this problem from the wrong angle, so if you can think of a better way, please speak up!